From 76ddc2e3e4837d0557fb6626394f87648e5f8c3b Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Tue, 30 Dec 2008 05:05:31 +0000 Subject: 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 --- libbb/xfuncs_printf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libbb') diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 108e140..46ae7ac 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -333,6 +333,29 @@ void FAST_FUNC xsetenv(const char *key, const char *value) bb_error_msg_and_die(bb_msg_memory_exhausted); } +/* Handles "VAR=VAL" strings, even those which are part of environ + * _right now_ + */ +void FAST_FUNC bb_unsetenv(const char *var) +{ + char *tp = strchr(var, '='); + + if (!tp) { + unsetenv(var); + return; + } + + /* In case var was putenv'ed, we can't replace '=' + * with NUL and unsetenv(var) - it won't work, + * env is modified by the replacement, unsetenv + * sees "VAR" instead of "VAR=VAL" and does not remove it! + * horror :( */ + tp = xstrndup(var, tp - var); + unsetenv(tp); + free(tp); +} + + // Die with an error message if we can't set gid. (Because resource limits may // limit this user to a given number of processes, and if that fills up the // setgid() will fail and we'll _still_be_root_, which is bad.) -- cgit v1.1