Re: wrong behaviour when unsetting/setting some variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 27/02/2024 02:07, Christoph Anton Mitterer wrote:
This works as expected in dash for most variables, but not some, e.g.:
$ env -i dash
$ export
export PWD='/home/calestyo'
$ export MAIL
$ export
export MAIL
export PWD='/home/calestyo'
$ unset -v MAIL
$ export
export MAIL
export PWD='/home/calestyo'
$

Same for MAILPATH and PATH, which made me believe it's perhaps an issue
in `changemail` and `changepath` as given in the struct `varinit` in
src/var.c.
But it also happens with IFS, PS1, PS2 and PS4, which have no function
listed there.
OTOH, it doesn’t happen with ATTY, TERM, LINENO and HISTSIZE.

I suspect the reason you don't see it happen with TERM, LINENO, and HISTSIZE is because you have built dash in a configuration in which these variables are not special. I do see it happen with all three of these. ATTY is dead code and is never special.

It looks like it is an incorrect handling of VSTRFIXED in setvareq(). The block

                if (((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) |
                     (vp->flags & VSTRFIXED)) == VUNSET) {

should not be entered, and is not, but this is the block that makes it work for normal variables. For special variables, we get to

  flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET);

where we preserve the VEXPORT of the previous value. In case of VUNSET, we should not be doing that. I agree with your expectations, unset should clear the export attribute.

VSTRFIXED is also used for local variables, so this explains what you see there too.

Cheers,
Harald van Dijk




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux