NetBSD Problem Report #26493
Received: (qmail 28541 invoked by uid 605); 31 Jul 2004 17:39:42 -0000
Message-Id: <E1BqxpZ-00002l-7J@quartz.newn.cam.ac.uk>
Date: Sat, 31 Jul 2004 18:39:37 +0100
From: prlw1@cam.ac.uk
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: prlw1@cam.ac.uk
To: gnats-bugs@gnats.NetBSD.org
Subject: pdksh misinterpretation of posix
X-Send-Pr-Version: 3.95
>Number: 26493
>Category: bin
>Synopsis: bug in pdksh backquote substitution
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jul 31 17:40:00 +0000 2004
>Closed-Date: Mon Oct 27 19:56:41 +0000 2008
>Last-Modified: Mon Oct 27 19:56:41 +0000 2008
>Originator: Patrick Welche
>Release: NetBSD 2.0G
>Organization:
>Environment:
@(#)PD KSH v5.2.14 99/07/13.2
from NetBSD-2.0G/i386
>Description:
The autotools wizards have shown me the error of our ksh's ways, and
pointed me to
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02__02
The Open Group Base Specifications Issue 6
IEEE Std 1003.1, 2004 Edition
2.2 Quoting
2.2.3 Double-Quotes
Enclosing characters in double-quotes ( "" ) shall preserve the
literal value of all characters within the double-quotes, with the
exception of the characters dollar sign, backquote, and backslash, as
follows:
...
`
The backquote shall retain its special meaning introducing the
other form of command substitution (see Command Substitution ).
The portion of the quoted string from the initial backquote and
the characters up to the next backquote that is not preceded by
a backslash, having escape characters removed, defines that
command whose output replaces "`...`" when the word is
expanded. Either of the following cases produces undefined
results:
+ A single-quoted or double-quoted string that begins, but does
not end, within the "`...`" sequence
+ A "`...`" sequence that begins, but does not end, within the
same double-quoted string
which is directly in opposition to what our ksh(1) man page says:
The following is a list of things that are affected by the state of the
posix option:
o \" inside double quoted `..` command substitutions: in posix
mode, the \" is interpreted when the command is interpreted; in
non-posix mode, the backslash is stripped before the command
substitution is interpreted. For example, echo "`echo \"hi\"`"
produces `"hi"' in posix mode, `hi' in non-posix mode. To avoid
problems, use the $(...) form of command substitution.
Looking at the standard above (c.f. "having escape characters
removed"), in posix mode, the command executed should be |echo "hi"|,
leading to |hi| being printed, (| used as quote) not |"hi"|.
This is in direct contradition to the man page.. (The shell's
behaviour is in accordance with the man page)
>How-To-Repeat:
>Fix:
- Need to agree that ksh's interpretation of POSIX is incorrect
- Then just look at line 326 of lex.c (v.1.10) where the assertion that
the string doesn't have escape characters removed in posix mode is
repeated
>Release-Note:
>Audit-Trail:
From: Alan Barrett <apb@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/26493 CVS commit: src/bin/ksh
Date: Mon, 27 Oct 2008 19:52:28 +0000 (UTC)
Module Name: src
Committed By: apb
Date: Mon Oct 27 19:52:28 UTC 2008
Modified Files:
src/bin/ksh: ksh.Man lex.c
Log Message:
In foo="`echo \"hi\"`", the backslashes should be removed by the outer
double quotes, not seen by the inner backquotes. Previously, ksh(1)
handled this correctly in non-posix mode but incorrectly in posix mode.
The previous comments in src/bin/ksh/lex.c quote parts of some version
of the POSIX specification. The version of POSIX being quoted is not
identified, but the wording is very similar to that in SUSv3
<http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html>.
It seems clear that the words "having escape characters removed"
mean, in that context, that the backslash before the double quote in
"...`...\"...`..." is removed as part of the handling of the outer
double quotes, so that the backslash is not present when the inner
backquotes are handled. The new code in this commit follows this
interpretation. The previous code followed a different interpretation
which is now believed to be incorrect.
Discussed in tech-userlevel. Closes PR 26493.
To generate a diff of this commit:
cvs rdiff -r1.20 -r1.21 src/bin/ksh/ksh.Man
cvs rdiff -r1.12 -r1.13 src/bin/ksh/lex.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: apb@NetBSD.org
State-Changed-When: Mon, 27 Oct 2008 19:56:41 +0000
State-Changed-Why:
change has been committed.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.