* stdlib/setenv.c (__add_to_environ):
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 Mar 2015 22:57:07 +0000 (15:57 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 13 Mar 2015 17:14:03 +0000 (10:14 -0700)
Dump core quickly if setenv (..., NULL, ...) is called.

ChangeLog
stdlib/setenv.c

index fb1591f..3b12552 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-13  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * stdlib/setenv.c (__add_to_environ):
+       Dump core quickly if setenv (..., NULL, ...) is called.
+
 2015-03-13  Roland McGrath  <roland@hack.frob.com>
 
        * sysdeps/arm/tls-macros.h: Include <sysdep.h>.
index b60c4f0..0534236 100644 (file)
@@ -114,8 +114,16 @@ __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 non-null.  Also, 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;