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
commit3eee6c6c9c6bff990c7c1142c7a5e5e160a3cc0c (patch)
tree4905cbe5179179f3b9b57dfb961d94135859c36c /src/lib/libc/stdlib/setenv.c
parent4f8fbb38b40bccdfd7a12640e2dd04b35e4e1133 (diff)
downloadopenbsd-3eee6c6c9c6bff990c7c1142c7a5e5e160a3cc0c.tar.gz
openbsd-3eee6c6c9c6bff990c7c1142c7a5e5e160a3cc0c.tar.bz2
openbsd-3eee6c6c9c6bff990c7c1142c7a5e5e160a3cc0c.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) {