diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2015-01-26 11:22:42 -0600 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2015-01-26 11:22:42 -0600 |
commit | f03fbbb009c0df52d363719a592e2ac33577d9a6 (patch) | |
tree | 01671bcc5099ef304faf5ae86d58bbf32f9d0b7c /libc/stdlib/setenv.c | |
parent | 97dc8cb71d96a4bbfda0aa51740433d5da825b6a (diff) | |
parent | 92de8a5f6ffb1ff9f7183fd08d872aa098b75ae2 (diff) |
merge upstream changes
Diffstat (limited to 'libc/stdlib/setenv.c')
-rw-r--r-- | libc/stdlib/setenv.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index 00e3f3d65..ecc302536 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -41,7 +41,7 @@ static char **last_environ; to reuse values once generated for a `setenv' call since we can never free the strings. [in uclibc, we do not] */ static int __add_to_environ(const char *name, const char *value, - int replace) + int replace) { register char **ep; register size_t size; @@ -76,7 +76,7 @@ static int __add_to_environ(const char *name, const char *value, /* We allocated this space; we can extend it. */ new_environ = realloc(last_environ, (size + 2) * sizeof(char *)); if (new_environ == NULL) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ goto DONE; } if (__environ != last_environ) { @@ -97,7 +97,7 @@ static int __add_to_environ(const char *name, const char *value, var_val = malloc(namelen + 1 + vallen); if (var_val == NULL) { - __set_errno(ENOMEM); + /* __set_errno(ENOMEM); */ goto DONE; } memcpy(var_val, name, namelen); @@ -116,6 +116,11 @@ static int __add_to_environ(const char *name, const char *value, int setenv(const char *name, const char *value, int replace) { + if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { + __set_errno(EINVAL); + return -1; + } + /* NB: setenv("VAR", NULL, 1) inserts "VAR=" string */ return __add_to_environ(name, value ? value : "", replace); } |