bin/56147: FreeBSD/NetBSD /bin/sh mishandles positional parameters
in "case"
Paul Jarc
prj at po.cwru.edu
Fri Aug 29 10:30:18 PDT 2003
>Number: 56147
>Category: bin
>Synopsis: FreeBSD/NetBSD /bin/sh mishandles positional parameters in "case"
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Aug 29 10:30:16 PDT 2003
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:
More information about the freebsd-bugs
mailing list