From 60b81b86c4b2eb3a0481176c344f4b6e7a6276fa Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Sun, 5 Jun 2016 12:15:27 -0700 Subject: 7076 segfault in putenv + getenv Reviewed by: Patrick Mooney Reviewed by: Dave Eddy Reviewed by: Cody Mello Reviewed by: Toomas Soome Reviewed by: Gordon Ross Reviewed by: Josef 'Jeff' Sipek Approved by: Dan McDonald --- usr/src/lib/libc/port/gen/getenv.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'usr/src/lib/libc') diff --git a/usr/src/lib/libc/port/gen/getenv.c b/usr/src/lib/libc/port/gen/getenv.c index c345226d0c..bd13a749ed 100644 --- a/usr/src/lib/libc/port/gen/getenv.c +++ b/usr/src/lib/libc/port/gen/getenv.c @@ -21,6 +21,7 @@ /* * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2016 Joyent, Inc. */ /* Copyright (c) 1988 AT&T */ @@ -336,6 +337,16 @@ addtoenv(char *string, int overwrite) int putenv(char *string) { + /* + * Historically a call to putenv() with no '=' in the string would work + * great until someone called getenv() on that particular environment + * variable again. As we've always treated this as valid, rather than + * teaching the rest of the environment code how to handle something + * without an '=' sign, it instead just calls unsetenv(). + */ + if (strchr(string, '=') == NULL) + return (unsetenv(string)); + return (addtoenv(string, 1)); } -- cgit v1.2.3