Fix __get_nprocs fgets_unlocked namespace (bug 17582)

Message ID alpine.DEB.2.10.1411112243360.12642@digraph.polyomino.org.uk
State Committed
Headers

Commit Message

Joseph Myers Nov. 11, 2014, 10:44 p.m. UTC
  __get_nprocs is called from malloc code, but calls fgets_unlocked,
which is not an ISO C or POSIX function.  This patch fixes it to call
a new __fgets_unlocked name instead.

Note: there are various other uses of fgets_unlocked in glibc's
libraries, and I haven't yet investigated which others might also be
problematic (called directly or indirectly from standard functions)
and so need to change to use __fgets_unlocked.

Tested for x86_64 (testsuite, and that disassembly of installed shared
libraries is unchanged by the patch).

2014-11-11  Joseph Myers  <joseph@codesourcery.com>

	[BZ #17582]
	* libio/iofgets.c [weak_alias && !_IO_MTSAFE_IO]
	(__fgets_unlocked): Add alias of _IO_fgets.  Use libc_hidden_def.
	* libio/iofgets_u.c (fgets_unlocked): Rename to __fgets_unlocked
	and define as weak alias of __fgets_unlocked.  Use
	libc_hidden_weak.
	(__fgets_unlocked): Use libc_hidden_def.
	* include/stdio.h (__fgets_unlocked): Declare.  Use
	libc_hidden_proto.
	* sysdeps/unix/sysv/linux/getsysstats.c (phys_pages_info): Use
	__fgets_unlocked instead of fgets_unlocked.
	* sysdeps/unix/sysv/linux/alpha/getsysstats.c
	(GET_NPROCS_CONF_PARSER): Likewise.
	* sysdeps/unix/sysv/linux/sparc/getsysstats.c
	(GET_NPROCS_CONF_PARSER): Likewise.
  

Comments

Roland McGrath Nov. 12, 2014, 9:57 p.m. UTC | #1
Looks OK.
  

Patch

diff --git a/include/stdio.h b/include/stdio.h
index 9f2ea31..ca859f5 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -151,6 +151,8 @@  libc_hidden_proto (fflush_unlocked)
 libc_hidden_proto (fread_unlocked)
 libc_hidden_proto (fwrite_unlocked)
 libc_hidden_proto (fgets_unlocked)
+extern __typeof (fgets_unlocked) __fgets_unlocked;
+libc_hidden_proto (__fgets_unlocked)
 libc_hidden_proto (fputs_unlocked)
 libc_hidden_proto (fmemopen)
 libc_hidden_proto (open_memstream)
diff --git a/libio/iofgets.c b/libio/iofgets.c
index 1b708ca..e352d09 100644
--- a/libio/iofgets.c
+++ b/libio/iofgets.c
@@ -73,6 +73,8 @@  _IO_fgets (buf, n, fp)
 weak_alias (_IO_fgets, fgets)
 
 # ifndef _IO_MTSAFE_IO
+strong_alias (_IO_fgets, __fgets_unlocked)
+libc_hidden_def (__fgets_unlocked)
 weak_alias (_IO_fgets, fgets_unlocked)
 libc_hidden_weak (fgets_unlocked)
 # endif
diff --git a/libio/iofgets_u.c b/libio/iofgets_u.c
index b2d4d8f..d338ee0 100644
--- a/libio/iofgets_u.c
+++ b/libio/iofgets_u.c
@@ -28,7 +28,7 @@ 
 #include <stdio.h>
 
 char *
-fgets_unlocked (buf, n, fp)
+__fgets_unlocked (buf, n, fp)
      char *buf;
      int n;
      _IO_FILE *fp;
@@ -66,4 +66,6 @@  fgets_unlocked (buf, n, fp)
   fp->_IO_file_flags |= old_error;
   return result;
 }
-libc_hidden_def (fgets_unlocked)
+libc_hidden_def (__fgets_unlocked)
+weak_alias (__fgets_unlocked, fgets_unlocked)
+libc_hidden_weak (fgets_unlocked)
diff --git a/sysdeps/unix/sysv/linux/alpha/getsysstats.c b/sysdeps/unix/sysv/linux/alpha/getsysstats.c
index 0b39d89..bc4abfe 100644
--- a/sysdeps/unix/sysv/linux/alpha/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/alpha/getsysstats.c
@@ -47,7 +47,7 @@ 
 	 the kernel will not generate them.  8192 bytes are really enough. \
 	 If there is no "CPUs ..." line then we are on a UP system.  */	   \
       (RESULT) = 1;							   \
-      while (fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL)	   \
+      while (__fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL)   \
 	if ((sscanf (buffer, "cpus detected : %d", &(RESULT)) == 1)	   \
 	    || (sscanf (buffer, "CPUs probed %d", &(RESULT)) == 1))	   \
 	  break;							   \
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 1746827..5b277e4 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -299,7 +299,7 @@  phys_pages_info (const char *format)
 	 string "processor".  We don't have to fear extremely long
 	 lines since the kernel will not generate them.  8192
 	 bytes are really enough.  */
-      while (fgets_unlocked (buffer, sizeof buffer, fp) != NULL)
+      while (__fgets_unlocked (buffer, sizeof buffer, fp) != NULL)
 	if (sscanf (buffer, format, &result) == 1)
 	  {
 	    result /= (__getpagesize () / 1024);
diff --git a/sysdeps/unix/sysv/linux/sparc/getsysstats.c b/sysdeps/unix/sysv/linux/sparc/getsysstats.c
index 8ec0a92..f28714c 100644
--- a/sysdeps/unix/sysv/linux/sparc/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/sparc/getsysstats.c
@@ -46,7 +46,7 @@ 
 	 probed cpus.  We don't have to fear extremely long lines since	 \
 	 the kernel will not generate them.  8192 bytes are really	 \
 	 enough.  */							 \
-      while (fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL)	 \
+      while (__fgets_unlocked ((BUFFER), sizeof (BUFFER), (FP)) != NULL) \
 	if (sscanf (buffer, "ncpus probed : %d", &(RESULT)) == 1)	 \
 	  break;							 \
     }									 \