diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-03-12 15:57:07 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-03-13 10:14:03 -0700 |
commit | 2ecccaede9097f867284d352a881d8f226ba4fb7 (patch) | |
tree | 3b108e62b75c4c596a309b4697fde584d39b91f4 /stdlib | |
parent | cdaf79d0af439ade496a1f6235f503e491502cd6 (diff) | |
download | glibc-2ecccaede9097f867284d352a881d8f226ba4fb7.zip glibc-2ecccaede9097f867284d352a881d8f226ba4fb7.tar.gz glibc-2ecccaede9097f867284d352a881d8f226ba4fb7.tar.bz2 |
* stdlib/setenv.c (__add_to_environ):
Dump core quickly if setenv (..., NULL, ...) is called.
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/setenv.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/stdlib/setenv.c b/stdlib/setenv.c index b60c4f0..0534236 100644 --- a/stdlib/setenv.c +++ b/stdlib/setenv.c @@ -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; |