sh: Fix use after free when resetting an in-use alias.

The special case of modifying an existing alias does not work correctly if
the alias is currently in use. Instead, handle this case by unaliasing the
old alias (if any) and then creating a new alias.
This commit is contained in:
Jilles Tjoelker 2017-04-16 22:10:02 +00:00
parent 683bf56cf6
commit 026dfd4aef
3 changed files with 10 additions and 10 deletions

View File

@ -63,17 +63,8 @@ setalias(const char *name, const char *val)
{
struct alias *ap, **app;
unalias(name);
app = hashalias(name);
for (ap = *app; ap; ap = ap->next) {
if (equal(name, ap->name)) {
INTOFF;
ckfree(ap->val);
ap->val = savestr(val);
INTON;
return;
}
}
/* not found */
INTOFF;
ap = ckmalloc(sizeof (struct alias));
ap->name = savestr(name);

View File

@ -24,6 +24,7 @@ ${PACKAGE}FILES+= alias14.0
${PACKAGE}FILES+= alias15.0 alias15.0.stdout
${PACKAGE}FILES+= alias16.0
${PACKAGE}FILES+= alias17.0
${PACKAGE}FILES+= alias18.0
${PACKAGE}FILES+= and-pipe-not.0
${PACKAGE}FILES+= case1.0
${PACKAGE}FILES+= case2.0

View File

@ -0,0 +1,8 @@
# $FreeBSD$
v=1
alias a='alias a=v=2
v=3
a'
eval a
[ "$v" = 2 ]