1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Do not export variables with dot names (re: 8e72608c)

Variables with a dot in their name, such as those declared in
namespace { ... } blocks, are usually stored in a separate tree
with their actual names not containing any dots. But under some
circumstances, including at least direct assignment of a
non-preexisting dot variable, dot variables are stored in the main
sh.var_tree with names actually containing dots. With allexport
active, those could end up exported to the environment. This bug
was also present in previous release versions of ksh.

src/cmd/ksh93/sh/name.c: pushnam():
- Check for a dot in the name before pushing a variable to export.
This commit is contained in:
Martijn Dekker 2022-02-05 15:04:12 +00:00
parent a8dd1bbd9d
commit 493a31053e
6 changed files with 28 additions and 4 deletions

View file

@ -169,7 +169,7 @@ const struct shtable3 shtab_builtins[] =
const char sh_set[] =
"[a?All variables that are assigned a value while this option is on are "
"automatically exported.]"
"automatically exported, unless they have a dot in their name.]"
"[b?The shell writes a message to standard error as soon it detects that "
"a background job completes rather than waiting until the next prompt.]"
"[e?A simple command that has an non-zero exit status will cause the shell "

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2022-02-04" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2022-02-05" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -7388,7 +7388,12 @@ See \f2History Expansion\fP above.
.TP 8
.B \-a
All variables that are assigned a value while this option is on
are automatically exported.
are automatically exported, unless they have a dot in their name.
Variables created in namespaces declared with the
.B namespace
keyword (see
.I Name Spaces
above) are only exported while their name space is active.
.TP 8
.B \-b
Prints job completion messages as soon as a background job changes

View file

@ -2197,10 +2197,15 @@ static void attstore(register Namval_t *np, void *data)
ap->attval = strcopy(++ap->attval,nv_name(np));
}
/*
* Called from sh_envgen() to push an individual variable to export
*/
static void pushnam(Namval_t *np, void *data)
{
register char *value;
register struct adata *ap = (struct adata*)data;
if(strchr(np->nvname,'.'))
return;
ap->tp = 0;
if(nv_isattr(np,NV_IMPORT) && np->nvenv)
*ap->argnam++ = np->nvenv;
@ -2213,7 +2218,6 @@ static void pushnam(Namval_t *np, void *data)
/*
* Generate the environment list for the child.
*/
char **sh_envgen(void)
{
register char **er;

View file

@ -728,6 +728,13 @@ exp='typeset -x bar=2'
got=$(typeset -p bar)
[[ $got == "$exp" ]] || err_exit 'Variable ${bar} should be exported' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
.foo=
.foo.bar=baz
exp=''
got=$(env | grep '^\.foo[.=]')
[[ $got == "$exp" ]] || err_exit 'Variables with dots in name exported' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
unset .foo.bar .foo
set +o allexport
# ======