From ba53e391e204926a7a71b5a9848b928a56af0062 Mon Sep 17 00:00:00 2001 From: millert <> Date: Wed, 3 Jun 2009 15:52:16 +0000 Subject: Make putenv(), setenv() and unsetenv() standards compliant. The standard explicitly disallows passing setenv a name with a '=' in it but historic BSD behavior is to allow this but to ignore the '=' and anything after it. --- src/lib/libc/stdlib/getenv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/lib/libc/stdlib/getenv.c') diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c index 72367b34e2..5aff11c61a 100644 --- a/src/lib/libc/stdlib/getenv.c +++ b/src/lib/libc/stdlib/getenv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getenv.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */ +/* $OpenBSD: getenv.c,v 1.9 2009/06/03 15:52:16 millert Exp $ */ /* * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. @@ -31,7 +31,7 @@ #include #include -char *__findenv(const char *name, int *offset); +char *__findenv(const char *name, int len, int *offset); /* * __findenv -- @@ -43,18 +43,15 @@ char *__findenv(const char *name, int *offset); * This routine *should* be a static; don't use it. */ char * -__findenv(const char *name, int *offset) +__findenv(const char *name, int len, int *offset) { extern char **environ; - int len, i; + int i; const char *np; char **p, *cp; if (name == NULL || environ == NULL) return (NULL); - for (np = name; *np && *np != '='; ++np) - ; - len = np - name; for (p = environ; (cp = *p) != NULL; ++p) { for (np = name, i = len; i && *cp; i--) if (*cp++ != *np++) @@ -75,6 +72,9 @@ char * getenv(const char *name) { int offset; + const char *np; - return (__findenv(name, &offset)); + for (np = name; *np && *np != '='; ++np) + ; + return (__findenv(name, (int)(np - name), &offset)); } -- cgit v1.2.3-55-g6feb