summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
authormillert <>2022-08-08 22:40:03 +0000
committermillert <>2022-08-08 22:40:03 +0000
commit70837e3e4d47bc74e2f1c690564b3fcd50608ac4 (patch)
tree4905cbe5179179f3b9b57dfb961d94135859c36c /src/lib/libc/stdlib/setenv.c
parentbcc4200a295f286ca7d94ff31b90b60e1c647e70 (diff)
downloadopenbsd-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@
Diffstat (limited to 'src/lib/libc/stdlib/setenv.c')
-rw-r--r--src/lib/libc/stdlib/setenv.c7
1 files changed, 4 insertions, 3 deletions
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) {