diff options
author | jeremy <> | 2012-09-23 16:08:04 +0000 |
---|---|---|
committer | jeremy <> | 2012-09-23 16:08:04 +0000 |
commit | 0b4a0e4e11684e4650c59945fb75c66fb9b1b5ac (patch) | |
tree | 5fc6f13012f9a99328860106c8e96f6183e97233 /src/lib/libc/stdlib/setenv.c | |
parent | 64dd23ac75bf38a89754b9ffbc87748f35f0ce44 (diff) | |
download | openbsd-0b4a0e4e11684e4650c59945fb75c66fb9b1b5ac.tar.gz openbsd-0b4a0e4e11684e4650c59945fb75c66fb9b1b5ac.tar.bz2 openbsd-0b4a0e4e11684e4650c59945fb75c66fb9b1b5ac.zip |
Make setenv(3) consistent with unsetenv(3), giving EINVAL if passed
an empty name, NULL pointer, or a name containing an '=' character.
OK millert@, guenther@
Diffstat (limited to 'src/lib/libc/stdlib/setenv.c')
-rw-r--r-- | src/lib/libc/stdlib/setenv.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c index 089ab92d38..9060fdba88 100644 --- a/src/lib/libc/stdlib/setenv.c +++ b/src/lib/libc/stdlib/setenv.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: setenv.c,v 1.13 2010/08/23 22:31:50 millert Exp $ */ | 1 | /* $OpenBSD: setenv.c,v 1.14 2012/09/23 16:08:04 jeremy Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 1987 Regents of the University of California. | 3 | * Copyright (c) 1987 Regents of the University of California. |
4 | * All rights reserved. | 4 | * All rights reserved. |
@@ -94,14 +94,16 @@ setenv(const char *name, const char *value, int rewrite) | |||
94 | const char *np; | 94 | const char *np; |
95 | int l_value, offset = 0; | 95 | int l_value, offset = 0; |
96 | 96 | ||
97 | if (!name || !*name) { | ||
98 | errno = EINVAL; | ||
99 | return (-1); | ||
100 | } | ||
97 | for (np = name; *np && *np != '='; ++np) | 101 | for (np = name; *np && *np != '='; ++np) |
98 | ; | 102 | ; |
99 | #ifdef notyet | ||
100 | if (*np) { | 103 | if (*np) { |
101 | errno = EINVAL; | 104 | errno = EINVAL; |
102 | return (-1); /* has `=' in name */ | 105 | return (-1); /* has `=' in name */ |
103 | } | 106 | } |
104 | #endif | ||
105 | 107 | ||
106 | l_value = strlen(value); | 108 | l_value = strlen(value); |
107 | if ((C = __findenv(name, (int)(np - name), &offset)) != NULL) { | 109 | if ((C = __findenv(name, (int)(np - name), &offset)) != NULL) { |