Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2012 10:18:05 GMT
From:      "Daniel F." <daniel.forsstrom[at]pp.inet.fi@FreeBSD.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/173418: /bin/sh - Alias breaks if set twice.
Message-ID:  <201211061018.qA6AI5q2086246@red.freebsd.org>
Resent-Message-ID: <201211061020.qA6AK1jo007925@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         173418
>Category:       bin
>Synopsis:       /bin/sh - Alias breaks if set twice.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 06 10:20:01 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Daniel F.
>Release:        9.0-RELEASE i386
>Organization:
>Environment:
FreeBSD freebsd 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:15:25 UTC 2012     root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
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.
>How-To-Repeat:
$/bin/sh
$alias a=b
$alias a=b
$alias

Or by sourcing a file with alias definitions, twice.
>Fix:
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)) {
 			INTOFF;
 			ckfree(ap->val);
+#ifdef notyet
 			ap->val	= savestr(val);
+#else
+			{
+			size_t vlen = strlen(val);
+			ap->val = ckmalloc(vlen + 2);
+			memcpy(ap->val, val, vlen);
+			ap->val[vlen] = ' ';
+			ap->val[vlen+1] = '\0';
+			}
+#endif
 			INTON;
 			return;
 		}


>Release-Note:
>Audit-Trail:
>Unformatted:



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