aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-04-19 01:06:33 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-04-19 01:07:31 -0700
commit03c1e456b079929a8290aeb4aadb05c0df73bfd2 (patch)
tree623a6bf41a61e08caffed4a2914bac4947c162ab
parent2bd2cad9e8a410643e80efa0b15f6f2882e1271b (diff)
downloadglibc-03c1e456b079929a8290aeb4aadb05c0df73bfd2.tar
glibc-03c1e456b079929a8290aeb4aadb05c0df73bfd2.tar.gz
glibc-03c1e456b079929a8290aeb4aadb05c0df73bfd2.tar.bz2
glibc-03c1e456b079929a8290aeb4aadb05c0df73bfd2.zip
Better fix for setenv (..., NULL, ...)
* stdlib/setenv.c (__add_to_environ): Dump core quickly if setenv (..., NULL, ...) is called. This time, do it the right way, and pacify GCC with a pragma.
-rw-r--r--ChangeLog6
-rw-r--r--stdlib/setenv.c18
2 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 0b648bfb11..a1d49cb3ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-19 Paul Eggert <eggert@cs.ucla.edu>
+
+ * stdlib/setenv.c (__add_to_environ):
+ Dump core quickly if setenv (..., NULL, ...) is called.
+ This time, do it the right way, and pacify GCC with a pragma.
+
2015-04-17 Roland McGrath <roland@hack.frob.com>
* elf/dl-close.c (_dl_close_worker) [DL_NNS == 1]: Just assert that
diff --git a/stdlib/setenv.c b/stdlib/setenv.c
index b60c4f0151..184a8cdd07 100644
--- a/stdlib/setenv.c
+++ b/stdlib/setenv.c
@@ -19,6 +19,13 @@
# include <config.h>
#endif
+/* Pacify GCC; see the commentary about VALLEN below. This is needed
+ at least through GCC 4.9.2. Pacify GCC for the entire file, as
+ there seems to be no way to pacify GCC selectively, only for the
+ place where it's needed. Do not use DIAG_IGNORE_NEEDS_COMMENT
+ here, as it's not defined yet. */
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+
#include <errno.h>
#if !_LIBC
# if !defined errno && !defined HAVE_ERRNO_DECL
@@ -114,8 +121,17 @@ __add_to_environ (name, value, combined, replace)
{
char **ep;
size_t size;
+
+ /* Compute lengths before locking, so that the critical section is
+ less of a performance bottleneck. VALLEN is needed only if
+ COMBINED is null (unfortunately GCC is not smart enough to deduce
+ this; see the #pragma at the start of this file). Testing
+ COMBINED instead of VALUE causes setenv (..., NULL, ...) to dump
+ core now instead of corrupting memory later. */
const size_t namelen = strlen (name);
- const size_t vallen = value != NULL ? strlen (value) + 1 : 0;
+ size_t vallen;
+ if (combined == NULL)
+ vallen = strlen (value) + 1;
LOCK;