diff mbox series

var: Fix unexporting of local variables using unset

Message ID ZheUuMS9rReRzEY5@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series var: Fix unexporting of local variables using unset | expand

Commit Message

Herbert Xu April 11, 2024, 7:43 a.m. UTC
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 <calestyo@scientia.org>
Fixes: e3c9a7dd7097 ("[VAR] Move unsetvar functionality into setvareq")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Christoph Anton Mitterer April 11, 2024, 1:27 p.m. UTC | #1
On Thu, 2024-04-11 at 15:43 +0800, Herbert Xu wrote:
> Thanks for the reminder.  This patch should fix the problem.

Thanks for the patch :-)


Cheers,
Chris.
diff mbox series

Patch

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;