diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2017-04-16 21:42:43 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2017-04-16 21:42:43 +0000 |
commit | 773e27aeee7d59ff38be751ea59493f716f06185 (patch) | |
tree | d769e0db9263a9b41798def5c278483365b1670f /bin/sh | |
parent | 6fd94039ef6c02ab3ffa8d50b8216967cb6e4e84 (diff) | |
download | src-773e27aeee7d59ff38be751ea59493f716f06185.tar.gz src-773e27aeee7d59ff38be751ea59493f716f06185.zip |
sh: Fix unalias -a while an alias is currently in use.
It is a rare situation to modify aliases while an alias is currently in use,
but this is handled for plain unalias. Handle it for unalias -a as well.
Notes
Notes:
svn path=/head/; revision=317037
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/alias.c | 32 | ||||
-rw-r--r-- | bin/sh/tests/parser/alias17.0 | 7 |
2 files changed, 27 insertions, 12 deletions
diff --git a/bin/sh/alias.c b/bin/sh/alias.c index 7e03f86268be..e67ad649ff70 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -85,6 +85,14 @@ setalias(const char *name, const char *val) INTON; } +static void +freealias(struct alias *ap) +{ + ckfree(ap->name); + ckfree(ap->val); + ckfree(ap); +} + static int unalias(const char *name) { @@ -106,9 +114,7 @@ unalias(const char *name) else { INTOFF; *app = ap->next; - ckfree(ap->name); - ckfree(ap->val); - ckfree(ap); + freealias(ap); INTON; } aliases--; @@ -122,19 +128,21 @@ unalias(const char *name) static void rmaliases(void) { - struct alias *ap, *tmp; + struct alias *ap, **app; int i; INTOFF; for (i = 0; i < ATABSIZE; i++) { - ap = atab[i]; - atab[i] = NULL; - while (ap) { - ckfree(ap->name); - ckfree(ap->val); - tmp = ap; - ap = ap->next; - ckfree(tmp); + app = &atab[i]; + while (*app) { + ap = *app; + if (ap->flag & ALIASINUSE) { + *ap->name = '\0'; + app = &(*app)->next; + } else { + *app = ap->next; + freealias(ap); + } } } aliases = 0; diff --git a/bin/sh/tests/parser/alias17.0 b/bin/sh/tests/parser/alias17.0 new file mode 100644 index 000000000000..005eeb72dee4 --- /dev/null +++ b/bin/sh/tests/parser/alias17.0 @@ -0,0 +1,7 @@ +# $FreeBSD$ + +v=1 +alias a='unalias -a +v=2' +eval a +[ "$v" = 2 ] |