From: Christoph Anton Mitterer <calestyo@scientia.org>
To: dash@vger.kernel.org
Subject: wrong behaviour when unsetting/setting some variables
Date: Tue, 27 Feb 2024 03:07:33 +0100 [thread overview]
Message-ID: <43f0631aea36f6b49e5c3dfdfe481a5a2b1fec6c.camel@scientia.org> (raw)
Hey.
Forwarding this from my report (for the records) at:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1064874
POSIX describes[0] unset to:
> unset values and attributes of variables and functions
While the exact detials are perhaps a bit unclear (see the discussion
at [1], I
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
next reply other threads:[~2024-02-27 2:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 2:07 Christoph Anton Mitterer [this message]
2024-02-27 3:07 ` wrong behaviour when unsetting/setting some variables Harald van Dijk
2024-02-27 3:28 ` Christoph Anton Mitterer
2024-02-27 10:24 ` Harald van Dijk
2024-02-27 4:23 ` Lawrence Velázquez
2024-02-27 5:11 ` Christoph Anton Mitterer
2024-02-27 7:53 ` Lawrence Velázquez
2024-02-29 12:29 ` Christoph Anton Mitterer
2024-02-29 17:58 ` Martijn Dekker
2024-02-29 19:03 ` Christoph Anton Mitterer
2024-02-28 0:56 ` Harald van Dijk
2024-02-29 12:24 ` Christoph Anton Mitterer
2024-02-29 18:03 ` Martijn Dekker
2024-02-29 17:41 ` Martijn Dekker
2024-02-29 18:07 ` Harald van Dijk
2024-02-29 18:45 ` Martijn Dekker
2024-02-29 18:56 ` Harald van Dijk
2024-03-10 21:33 ` Martijn Dekker
2024-04-11 1:26 ` Christoph Anton Mitterer
2024-04-11 7:43 ` [PATCH] var: Fix unexporting of local variables using unset Herbert Xu
2024-04-11 13:27 ` Christoph Anton Mitterer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43f0631aea36f6b49e5c3dfdfe481a5a2b1fec6c.camel@scientia.org \
--to=calestyo@scientia.org \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox