bin/57554: sh(1) incorrect handling of quoted parameter expansion

Mark Valentine mark at
Fri Oct 3 17:40:17 PDT 2003

>Number:         57554
>Category:       bin
>Synopsis:       sh(1) incorrect handling of quoted parameter expansion
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 03 17:40:14 PDT 2003
>Originator:     Mark Valentine
>Release:        FreeBSD 4.8-STABLE i386
System: FreeBSD 4.8-STABLE FreeBSD 4.8-STABLE #6: Wed Jun 11 15:04:41 BST 2003 root at i386

	sh(1) incorrectly quotes the pattern word in parameter expansions
	involving prefix/suffix removal when the whole expansion is enclosed
	in double quotes:

	    $ foo='\{foo'
	    $ echo ${foo#\{}
	    \{foo			# correct (1) - pattern is {
	    $ echo ${foo#"\{"}
	    foo				# correct (2) - pattern is \{
	    $ echo "${foo#\{}"
	    foo				# WRONG - should be same as (1)

	IEEE Std 1003.1-2001 states that "Enclosing the full parameter
	expansion string in double-quotes shall not cause the [...] pattern
	characters to be quoted, whereas quoting characters within the braces
	shall have this effect."

	NOTE: there seems to be a related problem with our handling of
	${foo#{} - bash and ksh seem to expect a further matching } -
	but I haven't managed to figure out chapter and verse on that

	I initially came across this bug in the context of (foo='{foo' and
	"${foo#\{}" doing the wrong thing (real life scenario: FreeBSD-
	hosted NetBSD build falls over in distrib/utils/sysinst/,
	but the above example is a clearer illustration of the part I did
	manage to find chapter and verse on...

	NetBSD's sh(1) handles this correctly, if the code change can be
	identified...  (NOTE: possibly look at their parser.c rev 1.51 and
	1.52; my brain's shut down for the day.)

More information about the freebsd-bugs mailing list