From 70837e3e4d47bc74e2f1c690564b3fcd50608ac4 Mon Sep 17 00:00:00 2001 From: millert <> Date: Mon, 8 Aug 2022 22:40:03 +0000 Subject: For putenv(3), return an error if string starts with a '=' character. Both FreeBSD and NetBSD have this behavior. OK deraadt@ --- src/lib/libc/stdlib/setenv.c | 7 ++++--- 1 file changed, 4 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 15c550ba30..fc8e5b677f 100644 --- a/src/lib/libc/stdlib/setenv.c +++ b/src/lib/libc/stdlib/setenv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setenv.c,v 1.19 2016/09/21 04:38:56 guenther Exp $ */ +/* $OpenBSD: setenv.c,v 1.20 2022/08/08 22:40:03 millert Exp $ */ /* * Copyright (c) 1987 Regents of the University of California. * All rights reserved. @@ -48,9 +48,10 @@ putenv(char *str) for (cp = str; *cp && *cp != '='; ++cp) ; - if (*cp != '=') { + if (cp == str || *cp != '=') { + /* '=' is the first character of string or is missing. */ errno = EINVAL; - return (-1); /* missing `=' in string */ + return (-1); } if (__findenv(str, (int)(cp - str), &offset) != NULL) { -- cgit v1.2.3-55-g6feb