From 0b4a0e4e11684e4650c59945fb75c66fb9b1b5ac Mon Sep 17 00:00:00 2001 From: jeremy <> Date: Sun, 23 Sep 2012 16:08:04 +0000 Subject: 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@ --- src/lib/libc/stdlib/setenv.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/lib/libc/stdlib/setenv.c') 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 @@ -/* $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) { -- cgit v1.2.3-55-g6feb