From prj@datasink.webmonster.de  Fri Aug 29 10:27:37 2003
Return-Path: <prj@datasink.webmonster.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CFF9416A4BF
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Aug 2003 10:27:37 -0700 (PDT)
Received: from mail.webmonster.de (datasink.webmonster.de [194.162.162.209])
	by mx1.FreeBSD.org (Postfix) with SMTP id 7D6EF43FCB
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Aug 2003 10:27:36 -0700 (PDT)
	(envelope-from prj@datasink.webmonster.de)
Received: (qmail 25055 invoked by uid 1018); 29 Aug 2003 17:27:57 -0000
Message-Id: <20030829172757.25054.qmail@mail.webmonster.de>
Date: 29 Aug 2003 17:27:57 -0000
From: Paul Jarc <prj@po.cwru.edu>
Reply-To: Paul Jarc <prj@po.cwru.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Paul Jarc <prj@po.cwru.edu>
Subject: FreeBSD/NetBSD /bin/sh mishandles positional parameters in "case"
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         56147
>Category:       bin
>Synopsis:       FreeBSD/NetBSD /bin/sh mishandles positional parameters in "case"
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    stefanf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 29 10:30:16 PDT 2003
>Closed-Date:    Wed Nov 22 00:32:05 GMT 2006
>Last-Modified:  Wed Nov 22 00:32:05 GMT 2006
>Originator:     Paul Jarc
>Release:        FreeBSD 4.8-STABLE i386
>Organization:
>Environment:
System: FreeBSD datasink.webmonster.de 4.8-STABLE FreeBSD 4.8-STABLE #5: Wed Aug 6 10:27:33 CEST 2003 root@datasink.webmonster.de:/m/ad0s1e/build/obj/m/ad0s1e/build/src/sys/DATASINKv2 i386


	
>Description:
In /bin/sh "case" patterns, wildcards are supposed to be interpreted as
literal characters if they are quoted or are the result of an expansion.
However, if they appear in the expansion of a positional parameter, they
are interpreted as wildcards.  This can cause scripts to fail silently
and mysteriously.
>How-To-Repeat:
$ sh -c 'set "*"; case x in "$1") echo oops;; esac'
oops
>Fix:
As a workaround, you can assign the value of the positional parameter to
a named parameter, and expand that named parameter in the "case" pattern:
$ sh -c 'set "*"; v=$1; case x in "$v") echo oops;; esac'
>Release-Note:
>Audit-Trail:

From: Robert Drehmel <robert@zoot.drehmel.com>
To: freebsd-gnats-submit@FreeBSD.org, prj@po.cwru.edu
Cc:  
Subject: Re: bin/56147: FreeBSD/NetBSD /bin/sh mishandles positional parameters in "case"
Date: Wed, 17 Sep 2003 16:01:27 +0200

 Hello.
 
 Does the attached patch fix your problem?
 (patch against -CURRENT's version)
 
 ciao,
 -robert
 
 Index: expand.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/sh/expand.c,v
 retrieving revision 1.45
 diff -u -r1.45 expand.c
 --- expand.c	3 Aug 2003 04:28:10 -0000	1.45
 +++ expand.c	17 Sep 2003 13:06:19 -0000
 @@ -637,7 +637,7 @@
  	int easy;
  	int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
  
 -	varflags = *p++;
 +	varflags = (unsigned char)*p++;
  	subtype = varflags & VSTYPE;
  	var = p;
  	special = 0;
 @@ -673,7 +673,8 @@
  	if (set && subtype != VSPLUS) {
  		/* insert the value of the variable */
  		if (special) {
 -			varvalue(var, varflags & VSQUOTE, flag & EXP_FULL);
 +			varvalue(var, varflags & VSQUOTE,
 +			    flag & (EXP_FULL | EXP_CASE));
  			if (subtype == VSLENGTH) {
  				varlen = expdest - stackblock() - startloc;
  				STADJUST(-varlen, expdest);

From: prj@po.cwru.edu (Paul Jarc)
To: Robert Drehmel <robert@zoot.drehmel.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/56147: FreeBSD/NetBSD /bin/sh mishandles positional parameters
 in "case"
Date: Wed, 17 Sep 2003 10:56:11 -0400

 Robert Drehmel <robert@zoot.drehmel.com> wrote:
 > Does the attached patch fix your problem?
 
 I don't have a FreeBSD system of my own to test it on.  If it fixes
 the test case I gave, I'm happy.
 
 
 paul
Responsible-Changed-From-To: freebsd-bugs->stefanf 
Responsible-Changed-By: stefanf 
Responsible-Changed-When: Tue Nov 7 22:46:53 UTC 2006 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=56147 
State-Changed-From-To: open->patched 
State-Changed-By: stefanf 
State-Changed-When: Tue Nov 7 22:47:07 UTC 2006 
State-Changed-Why:  
Finally patched in current.  Thanks for the report. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/56147: commit references a PR
Date: Tue,  7 Nov 2006 22:46:34 +0000 (UTC)

 stefanf     2006-11-07 22:46:14 UTC
 
   FreeBSD src repository
 
   Modified files:
     bin/sh               expand.c 
   Log:
   Fix expanding of quoted positional parameters in case patterns.
   
   Obtained from:  NetBSD (expand.c 1.58 and 1.59)
   Submitted by:   Paul Jarc
   PR:             56147
   
   Revision  Changes    Path
   1.51      +6 -6      src/bin/sh/expand.c
 _______________________________________________
 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:30:52 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6.  Thanks! 

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