From 480ebf43e85b2cfc31c433ee8bb3a723e44e9f9f Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 2 Jul 2024 11:33:08 +0100 Subject: win32: properly restore BB_ env vars Some BB_ shell variables get special treatment: they're updated in the environment immediately on any change. One case was missed: if such a variable was unset or not exported and was overridden by a local variable it wasn't unset in the environment when the local variable went out of scope. Add the code required to do this. Adds 48-64 bytes. (GitHub issue #423) --- shell/ash.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 9ef8f7742..b894a2314 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10948,6 +10948,9 @@ poplocalvars(int keep) struct localvar_list *ll; struct localvar *lvp, *next; struct var *vp; +#if ENABLE_PLATFORM_MINGW32 + int var_type; +#endif INT_OFF; ll = localvar_stack; @@ -10991,8 +10994,15 @@ poplocalvars(int keep) vp->flags = lvp->flags; vp->var_text = lvp->text; #if ENABLE_PLATFORM_MINGW32 - if (is_bb_var(lvp->text) == BB_VAR_ASSIGN) + var_type = is_bb_var(lvp->text); + if (var_type == BB_VAR_ASSIGN && (lvp->flags & VEXPORT)) putenv(lvp->text); + else if (var_type) { + char *var = xstrdup(lvp->text); + *strchrnul(var, '=') = '\0'; + unsetenv(var); + free(var); + } #endif } free(lvp); -- cgit v1.2.3-55-g6feb