summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXishi Qiu <qiuxishi@huawei.com>2014-11-04 19:26:28 +0800
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2015-01-23 20:59:27 +0100
commit217f0a86c07beae6a27d422b5f46ee853f3a447a (patch)
treedd320393d0004787a6c530493f1af43441c1bdff
parenta952a1dd2bba69da4c52a111600f4279aadc3602 (diff)
add argument check in setenv()
setenv() in glibc/eglibc will check the argument, like this, ... if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) { __set_errno (EINVAL); return -1; } ... So add argument check in uclibc's setenv() too. Signed-off-by: Xishi Qiu <qiuxishi@huawei.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r--libc/stdlib/setenv.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c
index f3b53b6c5..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;
@@ -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);
}