bin/173418: /bin/sh - Alias breaks if set twice.

Daniel F. daniel.forsstrom
Tue Nov 6 10:20:01 UTC 2012

>Number:         173418
>Category:       bin
>Synopsis:       /bin/sh - Alias breaks if set twice.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 06 10:20:01 UTC 2012
>Originator:     Daniel F.
>Release:        9.0-RELEASE i386
FreeBSD freebsd 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:15:25 UTC 2012     root at  i386
Function setalias() in alias.c of bin/sh uses a hack to avoid alias recursion by appending a single space character to alias value. This does not happen when we're redefining already existing alias.

When we execute or view aliases, the last character gets stripped in order to get rid of the extra space. In case of redefined alias this will become a problem.
$alias a=b
$alias a=b

Or by sourcing a file with alias definitions, twice.
Use the hack in part of code where it checks if alias already exists.

Patch attached with submission follows:

--- alias.c.orig	2012-11-05 21:49:57.000000000 +0200
+++ alias.c	2012-11-05 21:50:03.000000000 +0200
@@ -68,7 +68,17 @@
 		if (equal(name, ap->name)) {
+#ifdef notyet
 			ap->val	= savestr(val);
+			{
+			size_t vlen = strlen(val);
+			ap->val = ckmalloc(vlen + 2);
+			memcpy(ap->val, val, vlen);
+			ap->val[vlen] = ' ';
+			ap->val[vlen+1] = '\0';
+			}


More information about the freebsd-bugs mailing list