diff options
author | millert <> | 2022-08-08 22:40:03 +0000 |
---|---|---|
committer | millert <> | 2022-08-08 22:40:03 +0000 |
commit | 70837e3e4d47bc74e2f1c690564b3fcd50608ac4 (patch) | |
tree | 4905cbe5179179f3b9b57dfb961d94135859c36c | |
parent | bcc4200a295f286ca7d94ff31b90b60e1c647e70 (diff) | |
download | openbsd-70837e3e4d47bc74e2f1c690564b3fcd50608ac4.tar.gz openbsd-70837e3e4d47bc74e2f1c690564b3fcd50608ac4.tar.bz2 openbsd-70837e3e4d47bc74e2f1c690564b3fcd50608ac4.zip |
For putenv(3), return an error if string starts with a '=' character.
Both FreeBSD and NetBSD have this behavior. OK deraadt@
-rw-r--r-- | src/lib/libc/stdlib/getenv.3 | 8 | ||||
-rw-r--r-- | src/lib/libc/stdlib/setenv.c | 7 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/getenv.3 b/src/lib/libc/stdlib/getenv.3 index 1654d4257c..5a219a5c03 100644 --- a/src/lib/libc/stdlib/getenv.3 +++ b/src/lib/libc/stdlib/getenv.3 | |||
@@ -29,9 +29,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" $OpenBSD: getenv.3,v 1.22 2022/07/25 02:25:55 jsg Exp $ | 32 | .\" $OpenBSD: getenv.3,v 1.23 2022/08/08 22:40:03 millert Exp $ |
33 | .\" | 33 | .\" |
34 | .Dd $Mdocdate: July 25 2022 $ | 34 | .Dd $Mdocdate: August 8 2022 $ |
35 | .Dt GETENV 3 | 35 | .Dt GETENV 3 |
36 | .Os | 36 | .Os |
37 | .Sh NAME | 37 | .Sh NAME |
@@ -133,6 +133,10 @@ function was passed a | |||
133 | .Ar string | 133 | .Ar string |
134 | that did not contain an | 134 | that did not contain an |
135 | .Sq = | 135 | .Sq = |
136 | character, or was passed a | ||
137 | .Ar string | ||
138 | that started with the | ||
139 | .Sq = | ||
136 | character. | 140 | character. |
137 | .It Bq Er ENOMEM | 141 | .It Bq Er ENOMEM |
138 | The | 142 | The |
diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c index 15c550ba30..fc8e5b677f 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.19 2016/09/21 04:38:56 guenther Exp $ */ | 1 | /* $OpenBSD: setenv.c,v 1.20 2022/08/08 22:40:03 millert 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. |
@@ -48,9 +48,10 @@ putenv(char *str) | |||
48 | 48 | ||
49 | for (cp = str; *cp && *cp != '='; ++cp) | 49 | for (cp = str; *cp && *cp != '='; ++cp) |
50 | ; | 50 | ; |
51 | if (*cp != '=') { | 51 | if (cp == str || *cp != '=') { |
52 | /* '=' is the first character of string or is missing. */ | ||
52 | errno = EINVAL; | 53 | errno = EINVAL; |
53 | return (-1); /* missing `=' in string */ | 54 | return (-1); |
54 | } | 55 | } |
55 | 56 | ||
56 | if (__findenv(str, (int)(cp - str), &offset) != NULL) { | 57 | if (__findenv(str, (int)(cp - str), &offset) != NULL) { |