From emaste@FreeBSD.org  Thu Nov  2 18:31:12 2006
Return-Path: <emaste@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CA29216A492
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  2 Nov 2006 18:31:12 +0000 (UTC)
	(envelope-from emaste@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 88F5043D55
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  2 Nov 2006 18:31:12 +0000 (GMT)
	(envelope-from emaste@FreeBSD.org)
Received: from freefall.freebsd.org (emaste@localhost [127.0.0.1])
	by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id kA2IVCfN069785
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 2 Nov 2006 18:31:12 GMT
	(envelope-from emaste@freefall.freebsd.org)
Received: (from emaste@localhost)
	by freefall.freebsd.org (8.13.4/8.13.4/Submit) id kA2IVCTB069784;
	Thu, 2 Nov 2006 18:31:12 GMT
	(envelope-from emaste)
Message-Id: <200611021831.kA2IVCTB069784@freefall.freebsd.org>
Date: Thu, 2 Nov 2006 18:31:12 GMT
From: Ed Maste <emaste@FreeBSD.org>
Reply-To: Ed Maste <emaste@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: sh(1) aborts on invalid substitution in a not-taken if statement
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         105078
>Category:       bin
>Synopsis:       sh(1) aborts on invalid substitution in a not-taken if statement
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    stefanf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 02 18:40:17 GMT 2006
>Closed-Date:    Wed Nov 22 00:33:19 GMT 2006
>Last-Modified:  Wed Nov 22 00:33:19 GMT 2006
>Originator:     Ed Maste
>Release:        FreeBSD 6.0-STABLE i386
>Organization:
FreeBSD
>Environment:
System: FreeBSD freefall.freebsd.org 6.0-STABLE FreeBSD 6.0-STABLE #0: Sat Dec 10 03:18:20 UTC 2005 kensmith@freefall.freebsd.org:/usr/obj/usr/src/sys/FREEFALL i386

>Description:
It seems our sh(1) attempts to evaluate variable substitutions inside of an if statement
even if the statement evaluates to false.

I discovered this with a shell script that encapsulated some Linux sh-isms inside of a
check based on uname -s, and our sh aborted on those statements.  That shell script was
using a substring of the form ${var:1:3}, but I've used an intentionally bogus
substitution of ${} in the example below.

For reference, I observed the same behaviour with NetBSD's sh.  My Debian box produced
no error.  (I'm not sure what sh variant it has installed as /bin/sh.)  Solaris 10 was
also silent (thanks rwatson for checking).

>How-To-Repeat:
$ /bin/sh -c 'if false; then x=${}; fi'
Syntax error: Bad substitution

>Fix:

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->stefanf 
Responsible-Changed-By: stefanf 
Responsible-Changed-When: Sun Nov 5 18:36:29 UTC 2006 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105078 
State-Changed-From-To: open->patched 
State-Changed-By: stefanf 
State-Changed-When: Sun Nov 5 18:36:51 UTC 2006 
State-Changed-Why:  
Fixed in current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=105078 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/105078: commit references a PR
Date: Sun,  5 Nov 2006 18:36:19 +0000 (UTC)

 stefanf     2006-11-05 18:36:05 UTC
 
   FreeBSD src repository
 
   Modified files:
     bin/sh               expand.c parser.c parser.h 
   Log:
   When parsing an invalid parameter expansion (eg. ${} or ${foo@bar}) do not
   issue a syntax error immediately but save the information that it is erroneous
   for later when the parameter expansion is actually done.  This means eg. "false
   && ${}" will not generate an error which seems to be required by POSIX.
   Include the invalid parameter expansion in the error message (sometimes
   abbreviated with ... because recovering it would require a lot of code).
   
   PR:             105078
   Submitted by:   emaste
   
   Revision  Changes    Path
   1.50      +5 -0      src/bin/sh/expand.c
   1.58      +19 -9     src/bin/sh/parser.c
   1.11      +1 -0      src/bin/sh/parser.h
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: stefanf 
State-Changed-When: Wed Nov 22 00:33:02 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6.  Thanks! 

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