#1064874 wrong behaviour when unsetting/setting some variables

Package:
dash
Source:
dash
Description:
POSIX-compliant shell
Submitter:
Christoph Anton Mitterer
Date:
2024-02-27 02:06:04 UTC
Severity:
normal
Tags:
#1064874#5
Date:
2024-02-27 02:03:19 UTC
From:
To:
Hey.

POSIX describes[0] unset to:
think it is rather clear that unset, on a variable that has no readonly attribute,
shall case the variable/value binding AND any attributes to be unset.


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.

The consequence of that is at least, that one has no chance to fully unset these
variables, and even if they loose their value, they’ll be exported to executed
commands, possibly altering their behaviour.


I think a similar problem exists when using local variables, but there it's even
worse as it seems to affect any variable names:
```
f()
{
	export
	echo

	local FOO=v
	export FOO
	export
	echo

	unset -v FOO
	export
}

f
```
gives:
```
export PWD='/home/calestyo'

export FOO='v'
export PWD='/home/calestyo'

export FOO
export PWD='/home/calestyo'

```
and presumaby that `FOO` would then be exported to executed commands.


Cheers,
Chris.


[0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset
[1] https://austingroupbugs.net/view.php?id=1806