diff options
author | bde <bde@FreeBSD.org> | 2002-04-25 20:25:15 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 2002-04-25 20:25:15 +0000 |
commit | e1e6cfc088b5b6b533f828ec8eb7bef1a60aab18 (patch) | |
tree | 2539c33ca636de75a80e4b652b17667880a84ef4 /sys/kern/kern_environment.c | |
parent | 8c92a5594973607d48324a5cff1f21cc9b8b0bd3 (diff) | |
download | FreeBSD-src-e1e6cfc088b5b6b533f828ec8eb7bef1a60aab18.zip FreeBSD-src-e1e6cfc088b5b6b533f828ec8eb7bef1a60aab18.tar.gz |
Fixed some longstanding bugs in _getenv_static():
- malformed environment strings (ones without an '=') were not rejected.
There shouldn't be any of these, but when the static environment is
empty it always begins with one of these; this one should be considered
as the terminator after the end of the environment, but it isn't.
- the comparison of the name being looked up with the name in the
environment was fuzzy -- only the characters up to the length of the
latter were compared, so _getenv_static("foobar") matched "foo=..."
in the environment and everything matched "" in the empty environment.
MFC after: 3 days
Diffstat (limited to 'sys/kern/kern_environment.c')
-rw-r--r-- | sys/kern/kern_environment.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c index 8c4d7dc..a5c5e08 100644 --- a/sys/kern/kern_environment.c +++ b/sys/kern/kern_environment.c @@ -238,10 +238,11 @@ _getenv_static(const char *name) for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) { for (ep = cp; (*ep != '=') && (*ep != 0); ep++) ; + if (*ep != '=') + continue; len = ep - cp; - if (*ep == '=') - ep++; - if (!strncmp(name, cp, len)) + ep++; + if (!strncmp(name, cp, len) && name[len] == 0) return (ep); } return (NULL); |