Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Make putenv(3) fails with EINVAL for a null pointer, or for ...
details: https://anonhg.NetBSD.org/src/rev/d2a9e4eaa746
branches: trunk
changeset: 758199:d2a9e4eaa746
user: njoly <njoly%NetBSD.org@localhost>
date: Mon Oct 25 20:35:36 2010 +0000
description:
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.
diffstat:
lib/libc/stdlib/getenv.3 | 11 +++++++++--
lib/libc/stdlib/putenv.c | 8 +++++---
tests/lib/libc/stdlib/t_environment.c | 9 ++++++---
3 files changed, 20 insertions(+), 8 deletions(-)
diffs (92 lines):
diff -r 6b9cb3ced3e9 -r d2a9e4eaa746 lib/libc/stdlib/getenv.3
--- a/lib/libc/stdlib/getenv.3 Mon Oct 25 17:49:36 2010 +0000
+++ b/lib/libc/stdlib/getenv.3 Mon Oct 25 20:35:36 2010 +0000
@@ -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 @@
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
diff -r 6b9cb3ced3e9 -r d2a9e4eaa746 lib/libc/stdlib/putenv.c
--- a/lib/libc/stdlib/putenv.c Mon Oct 25 17:49:36 2010 +0000
+++ b/lib/libc/stdlib/putenv.c Mon Oct 25 20:35:36 2010 +0000
@@ -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 @@
_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;
diff -r 6b9cb3ced3e9 -r d2a9e4eaa746 tests/lib/libc/stdlib/t_environment.c
--- a/tests/lib/libc/stdlib/t_environment.c Mon Oct 25 17:49:36 2010 +0000
+++ b/tests/lib/libc/stdlib/t_environment.c Mon Oct 25 20:35:36 2010 +0000
@@ -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 @@
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)
Home |
Main Index |
Thread Index |
Old Index