Browse Source

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@
OPENBSD_5_3
jeremy 12 years ago
parent
commit
803376ceaa
2 changed files with 10 additions and 20 deletions
  1. +5
    -17
      src/lib/libc/stdlib/getenv.3
  2. +5
    -3
      src/lib/libc/stdlib/setenv.c

+ 5
- 17
src/lib/libc/stdlib/getenv.3 View File

@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $OpenBSD: getenv.3,v 1.17 2012/06/02 00:14:16 guenther Exp $
.\" $OpenBSD: getenv.3,v 1.18 2012/09/23 16:08:04 jeremy Exp $
.\"
.Dd $Mdocdate: June 2 2012 $
.Dd $Mdocdate: September 23 2012 $
.Dt GETENV 3
.Os
.Sh NAME
@ -53,14 +53,6 @@
.Sh DESCRIPTION
These functions set, unset, and fetch environment variables from the host
.Em environment list .
For compatibility with differing environment conventions, the given argument
.Fa name
may be appended with an equal sign
.Dq Li \&=
followed by zero or more characters,
and
.Fa value
may be prepended with an equal sign.
.Pp
The
.Fn getenv
@ -125,19 +117,15 @@ The
.Fn setenv
or
.Fn unsetenv
function was passed a
function was passed an empty
.Ar name
or a NULL pointer, or was passed a
.Ar name
containing an
.Sq =
character.
.Pp
The
.Fn unsetenv
function was passed an empty
.Ar name
or a NULL pointer.
.Pp
The
.Fn putenv
function was passed a
.Ar string


+ 5
- 3
src/lib/libc/stdlib/setenv.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: setenv.c,v 1.13 2010/08/23 22:31:50 millert Exp $ */
/* $OpenBSD: setenv.c,v 1.14 2012/09/23 16:08:04 jeremy Exp $ */
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
@ -94,14 +94,16 @@ setenv(const char *name, const char *value, int rewrite)
const char *np;
int l_value, offset = 0;
if (!name || !*name) {
errno = EINVAL;
return (-1);
}
for (np = name; *np && *np != '='; ++np)
;
#ifdef notyet
if (*np) {
errno = EINVAL;
return (-1); /* has `=' in name */
}
#endif
l_value = strlen(value);
if ((C = __findenv(name, (int)(np - name), &offset)) != NULL) {


Loading…
Cancel
Save