From owner-freebsd-bugs@FreeBSD.ORG Tue Nov 6 10:20:01 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8FCA12BF for ; Tue, 6 Nov 2012 10:20:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 63AD68FC0C for ; Tue, 6 Nov 2012 10:20:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id qA6AK14g007926 for ; Tue, 6 Nov 2012 10:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id qA6AK1jo007925; Tue, 6 Nov 2012 10:20:01 GMT (envelope-from gnats) Resent-Date: Tue, 6 Nov 2012 10:20:01 GMT Resent-Message-Id: <201211061020.qA6AK1jo007925@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Daniel F." Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 300452A0 for ; 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 ; 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 ; 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." To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: bin/173418: /bin/sh - Alias breaks if set twice. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Nov 2012 10:20:01 -0000 >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: