public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Fix crypt snprintf namespace (bug 20829)
@ 2016-11-16 19:05 Joseph Myers
  2016-11-16 19:42 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Myers @ 2016-11-16 19:05 UTC (permalink / raw)
  To: libc-alpha

Extending linknamespace tests to cover libcrypt showed that crypt
brings in references to snprintf, but is in XPG3 and XPG4 which don't
have snprintf.  This patch fixes it to use __snprintf instead,
exporting __snprintf from libc.so at version GLIBC_PRIVATE and adding
libc_hidden_proto / libc_hidden_def accordingly.

Tested for x86_64 and x86, in conjunction with the testsuite changes
to enable linknamespace testing for libdl and libcrypt.  Also tested
(compilation only) for powerpc to make sure there were no problem
interactions with the optional-long-double handling for snprintf.

2016-11-16  Joseph Myers  <joseph@codesourcery.com>

	[BZ #20829]
	* stdio-common/Versions (__snprintf): Add to version
	GLIBC_PRIVATE.
	* include/stdio.h (__snprintf): Use libc_hidden_proto.
	* stdio-common/snprintf.c (__snprintf): Use libc_hidden_def.
	* crypt/sha256-crypt.c (__sha256_crypt_r): Use __snprintf instead
	of snprintf.
	* crypt/sha512-crypt.c (__sha512_crypt_r): Likewise.

diff --git a/crypt/sha256-crypt.c b/crypt/sha256-crypt.c
index ca703de..d768234 100644
--- a/crypt/sha256-crypt.c
+++ b/crypt/sha256-crypt.c
@@ -319,8 +319,8 @@ __sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
 
   if (rounds_custom)
     {
-      int n = snprintf (cp, MAX (0, buflen), "%s%zu$",
-			sha256_rounds_prefix, rounds);
+      int n = __snprintf (cp, MAX (0, buflen), "%s%zu$",
+			  sha256_rounds_prefix, rounds);
       cp += n;
       buflen -= n;
     }
diff --git a/crypt/sha512-crypt.c b/crypt/sha512-crypt.c
index c42e5b7..f404c88 100644
--- a/crypt/sha512-crypt.c
+++ b/crypt/sha512-crypt.c
@@ -318,8 +318,8 @@ __sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
 
   if (rounds_custom)
     {
-      int n = snprintf (cp, MAX (0, buflen), "%s%zu$",
-			sha512_rounds_prefix, rounds);
+      int n = __snprintf (cp, MAX (0, buflen), "%s%zu$",
+			  sha512_rounds_prefix, rounds);
       cp += n;
       buflen -= n;
     }
diff --git a/include/stdio.h b/include/stdio.h
index 1ffbc40..30e737e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -11,6 +11,7 @@ extern int __fcloseall (void);
 extern int __snprintf (char *__restrict __s, size_t __maxlen,
 		       const char *__restrict __format, ...)
      __attribute__ ((__format__ (__printf__, 3, 4)));
+libc_hidden_proto (__snprintf)
 extern int __vsnprintf (char *__restrict __s, size_t __maxlen,
 			const char *__restrict __format, _G_va_list __arg)
      __attribute__ ((__format__ (__printf__, 3, 0)));
diff --git a/stdio-common/Versions b/stdio-common/Versions
index 06b96f6..5016f69 100644
--- a/stdio-common/Versions
+++ b/stdio-common/Versions
@@ -60,5 +60,7 @@ libc {
   GLIBC_PRIVATE {
     # global variables
     _itoa_lower_digits;
+    # Used in libcrypt.
+    __snprintf;
   }
 }
diff --git a/stdio-common/snprintf.c b/stdio-common/snprintf.c
index a3cc518..ce7ce06 100644
--- a/stdio-common/snprintf.c
+++ b/stdio-common/snprintf.c
@@ -35,4 +35,5 @@ __snprintf (char *s, size_t maxlen, const char *format, ...)
 
   return done;
 }
+libc_hidden_def (__snprintf)
 ldbl_weak_alias (__snprintf, snprintf)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix crypt snprintf namespace (bug 20829)
  2016-11-16 19:05 Fix crypt snprintf namespace (bug 20829) Joseph Myers
@ 2016-11-16 19:42 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2016-11-16 19:42 UTC (permalink / raw)
  To: Joseph Myers, libc-alpha

On 11/16/2016 08:05 PM, Joseph Myers wrote:

> 	[BZ #20829]
> 	* stdio-common/Versions (__snprintf): Add to version
> 	GLIBC_PRIVATE.
> 	* include/stdio.h (__snprintf): Use libc_hidden_proto.
> 	* stdio-common/snprintf.c (__snprintf): Use libc_hidden_def.
> 	* crypt/sha256-crypt.c (__sha256_crypt_r): Use __snprintf instead
> 	of snprintf.
> 	* crypt/sha512-crypt.c (__sha512_crypt_r): Likewise.

Looks good to me.  Thanks.

Florian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-16 19:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-16 19:05 Fix crypt snprintf namespace (bug 20829) Joseph Myers
2016-11-16 19:42 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).