libbb: add bb_unsetenv (taken from hush).

udhcpc: stop filtering environment passed to the script.
crond: fix uncovered potential bug (failing unsetenv)
mdev: fix uncovered potential bug (failing unsetenv)
tcp, udpsvd: fix uncovered potential bug (failing unsetenv)

function                                             old     new   delta
safe_setenv                                            -      58     +58
bb_unsetenv                                            -      55     +55
builtin_unset                                        139     138      -1
tcpudpsvd_main                                      1843    1830     -13
free_strings_and_unsetenv                             87      53     -34
udhcp_run_script                                    1186    1133     -53
safe_setenv4                                          62       -     -62
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 0/4 up/down: 113/-163)          Total: -50 bytes
This commit is contained in:
Denis Vlasenko
2008-12-30 05:05:31 +00:00
parent d6e8f9450c
commit 76ddc2e3e4
7 changed files with 65 additions and 57 deletions

View File

@@ -730,16 +730,8 @@ static void free_strings_and_unsetenv(char **strings, int unset)
v = strings;
while (*v) {
if (unset) {
char *copy;
/* *strchrnul(*v, '=') = '\0'; -- BAD
* In case *v was putenv'ed, we can't
* unsetenv(*v) after taking out '=':
* it won't work, env is modified by taking out!
* horror :( */
copy = xstrndup(*v, strchrnul(*v, '=') - *v);
debug_printf_env("unsetenv '%s'\n", copy);
unsetenv(copy);
free(copy);
debug_printf_env("unsetenv '%s'\n", *v);
bb_unsetenv(*v);
}
free(*v++);
}
@@ -2937,7 +2929,7 @@ static void unset_local_var(const char *name)
* is ro, and we cannot reach this code on the 1st pass */
prev->next = cur->next;
debug_printf_env("%s: unsetenv '%s'\n", __func__, cur->varstr);
unsetenv(cur->varstr);
bb_unsetenv(cur->varstr);
if (!cur->max_len)
free(cur->varstr);
free(cur);