Make putenv(3) fails with EINVAL for a null pointer, or for a string
that either miss or start with a `=' character. Adjust man page and testcase accordingly.
This commit is contained in:
parent
ac9dbb05ed
commit
5d63576039
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: getenv.3,v 1.23 2010/10/16 11:23:41 njoly Exp $
|
||||
.\" $NetBSD: getenv.3,v 1.24 2010/10/25 20:35:36 njoly Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1988, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -33,7 +33,7 @@
|
||||
.\"
|
||||
.\" from: @(#)getenv.3 8.2 (Berkeley) 12/11/93
|
||||
.\"
|
||||
.Dd October 16, 2010
|
||||
.Dd October 25, 2010
|
||||
.Dt GETENV 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -170,6 +170,13 @@ The
|
||||
argument to
|
||||
.Fn setenv
|
||||
is a null pointer.
|
||||
The
|
||||
.Fa string
|
||||
argument to
|
||||
.Fn putenv
|
||||
is a null pointer, or points to a string that either miss or start with a
|
||||
.Dq Li \&=
|
||||
character.
|
||||
.It Bq Er ENOMEM
|
||||
The function
|
||||
.Fn setenv
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: putenv.c,v 1.16 2010/10/05 02:23:38 enami Exp $ */
|
||||
/* $NetBSD: putenv.c,v 1.17 2010/10/25 20:35:36 njoly Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1993
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)putenv.c 8.2 (Berkeley) 3/27/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: putenv.c,v 1.16 2010/10/05 02:23:38 enami Exp $");
|
||||
__RCSID("$NetBSD: putenv.c,v 1.17 2010/10/25 20:35:36 njoly Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
@ -59,8 +59,10 @@ putenv(char *str)
|
||||
|
||||
_DIAGASSERT(str != NULL);
|
||||
|
||||
if (strchr(str, '=') == NULL)
|
||||
if (str == NULL || strchr(str, '=') == NULL || *str == '=') {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rwlock_wrlock(&__environ_lock) != 0)
|
||||
return -1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_environment.c,v 1.3 2010/10/16 11:23:41 njoly Exp $ */
|
||||
/* $NetBSD: t_environment.c,v 1.4 2010/10/25 20:35:36 njoly Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_environment.c,v 1.3 2010/10/16 11:23:41 njoly Exp $");
|
||||
__RCSID("$NetBSD: t_environment.c,v 1.4 2010/10/25 20:35:36 njoly Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <errno.h>
|
||||
@ -95,7 +95,10 @@ ATF_TC_BODY(t_putenv, tc)
|
||||
string[1] = 'r';
|
||||
unsetenv("crap");
|
||||
ATF_CHECK(getenv("crap") == NULL);
|
||||
|
||||
|
||||
ATF_CHECK_ERRNO(EINVAL, putenv(NULL) == -1);
|
||||
ATF_CHECK_ERRNO(EINVAL, putenv("val") == -1);
|
||||
ATF_CHECK_ERRNO(EINVAL, putenv("=val") == -1);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
|
Loading…
Reference in New Issue
Block a user