From nobody@FreeBSD.org  Tue Nov  6 10:18:06 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 300452A0
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 Nov 2012 10:18:06 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 175BB8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  6 Nov 2012 10:18:06 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qA6AI5UE086247
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 6 Nov 2012 10:18:05 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qA6AI5q2086246;
	Tue, 6 Nov 2012 10:18:05 GMT
	(envelope-from nobody)
Message-Id: <201211061018.qA6AI5q2086246@red.freebsd.org>
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/sh - Alias breaks if set twice.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173418
>Category:       bin
>Synopsis:       /bin/sh - Alias breaks if set twice.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 06 10:20:01 UTC 2012
>Closed-Date:    Fri Jun 28 21:54:04 UTC 2013
>Last-Modified:  Fri Jun 28 21:54:04 UTC 2013
>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:
Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Wed Nov 7 23:29:38 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173418 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Thu Nov 8 13:36:59 UTC 2012 
State-Changed-Why:  
Applied to 10-current, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173418 
State-Changed-From-To: patched->closed 
State-Changed-By: jilles 
State-Changed-When: Fri Jun 28 21:54:04 UTC 2013 
State-Changed-Why:  
Fixed in 10-current (r242766) and 9-stable (r243402). Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173418 
>Unformatted:
