diff options
author | Colin Percival <cperciva@FreeBSD.org> | 2009-02-16 21:56:17 +0000 |
---|---|---|
committer | Colin Percival <cperciva@FreeBSD.org> | 2009-02-16 21:56:17 +0000 |
commit | 3a5733c67b48c804bc1eb4190cea020b294b21a2 (patch) | |
tree | b9751cdf7057bf5fa358e8e5cb109ef63dab6a20 /contrib | |
parent | 78c0a9c9e287ddf484b296b3a995e520b29e3ec2 (diff) | |
download | src-test2-3a5733c67b48c804bc1eb4190cea020b294b21a2.tar.gz src-test2-3a5733c67b48c804bc1eb4190cea020b294b21a2.zip |
Notes
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/telnet/telnetd/sys_term.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/contrib/telnet/telnetd/sys_term.c b/contrib/telnet/telnetd/sys_term.c index 781e0d14c5e2..7b2dbdb2dfa3 100644 --- a/contrib/telnet/telnetd/sys_term.c +++ b/contrib/telnet/telnetd/sys_term.c @@ -1271,8 +1271,18 @@ scrub_env(void) char **cpp, **cpp2; const char **p; - - for (cpp2 = cpp = environ; *cpp; cpp++) { + char ** new_environ; + size_t count; + + /* Allocate space for scrubbed environment. */ + for (count = 1, cpp = environ; *cpp; count++, cpp++) + continue; + if ((new_environ = malloc(count * sizeof(char *))) == NULL) { + environ = NULL; + return; + } + + for (cpp2 = new_environ, cpp = environ; *cpp; cpp++) { int reject_it = 0; for(p = rej; *p; p++) @@ -1286,10 +1296,15 @@ scrub_env(void) for(p = acc; *p; p++) if(strncmp(*cpp, *p, strlen(*p)) == 0) break; - if(*p != NULL) - *cpp2++ = *cpp; + if(*p != NULL) { + if ((*cpp2++ = strdup(*cpp)) == NULL) { + environ = new_environ; + return; + } + } } *cpp2 = NULL; + environ = new_environ; } /* |