Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Apr 2017 21:42:44 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r317037 - in head/bin/sh: . tests/parser
Message-ID:  <201704162142.v3GLgin1035612@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Apr 16 21:42:43 2017
New Revision: 317037
URL: https://svnweb.freebsd.org/changeset/base/317037

Log:
  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.

Added:
  head/bin/sh/tests/parser/alias17.0   (contents, props changed)
Modified:
  head/bin/sh/alias.c

Modified: head/bin/sh/alias.c
==============================================================================
--- head/bin/sh/alias.c	Sun Apr 16 19:23:10 2017	(r317036)
+++ head/bin/sh/alias.c	Sun Apr 16 21:42:43 2017	(r317037)
@@ -85,6 +85,14 @@ setalias(const char *name, const char *v
 	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;

Added: head/bin/sh/tests/parser/alias17.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/bin/sh/tests/parser/alias17.0	Sun Apr 16 21:42:43 2017	(r317037)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+v=1
+alias a='unalias -a
+v=2'
+eval a
+[ "$v" = 2 ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201704162142.v3GLgin1035612>