summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
authorjeremy <>2012-09-23 16:08:04 +0000
committerjeremy <>2012-09-23 16:08:04 +0000
commitbe49cd9e087c09cea5ec0276d663efd8564fa0d5 (patch)
tree5fc6f13012f9a99328860106c8e96f6183e97233 /src/lib/libc/stdlib/setenv.c
parent50b3ad9ae18cc1107f1f3e50a3da6e97537c3651 (diff)
downloadopenbsd-be49cd9e087c09cea5ec0276d663efd8564fa0d5.tar.gz
openbsd-be49cd9e087c09cea5ec0276d663efd8564fa0d5.tar.bz2
openbsd-be49cd9e087c09cea5ec0276d663efd8564fa0d5.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.c8
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) {