[PATCH] var: Fix unexporting of local variables using unset

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On Thu, Apr 11, 2024 at 03:26:53AM +0200, Christoph Anton Mitterer wrote:
> 
> With all the recently merged patches... any chance that we get this
> issue(s) here fixed?
> Or at least those, where it's clear what should happen?

Thanks for the reminder.  This patch should fix the problem.

---8<---
Local variables and other variables with the flag VSTRFIXED set
could not be unexported using the unset command.  Fix this by
adding a special case in setvareq for them.

Reported-by: Christoph Anton Mitterer <[email protected]>
Fixes: e3c9a7dd7097 ("[VAR] Move unsetvar functionality into setvareq")
Signed-off-by: Herbert Xu <[email protected]>

diff --git a/src/var.c b/src/var.c
index 21e0abf..6f85be3 100644
--- a/src/var.c
+++ b/src/var.c
@@ -255,6 +255,8 @@ struct var *setvareq(char *s, int flags)
 	vpp = findvar(s);
 	vp = *vpp;
 	if (vp) {
+		unsigned bits;
+
 		if (vp->flags & VREADONLY) {
 			const char *n;
 
@@ -274,8 +276,11 @@ struct var *setvareq(char *s, int flags)
 		if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
 			ckfree(vp->text);
 
-		if (((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) |
-		     (vp->flags & VSTRFIXED)) == VUNSET) {
+		if ((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) != VUNSET)
+			bits = ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET);
+		else if ((vp->flags & VSTRFIXED))
+			bits = VSTRFIXED;
+		else {
 			*vpp = vp->next;
 			ckfree(vp);
 out_free:
@@ -284,7 +289,7 @@ out_free:
 			goto out;
 		}
 
-		flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET);
+		flags |= vp->flags & bits;
 	} else {
 		if (flags & VNOSET)
 			goto out;
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.