1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Allow double quotes within backtick comsub within double quotes

The following reproducer causes a spurious syntax error:

    foo="`: "("`"

The nested double quotes are not recognised correctly, causing a
syntax error at the '('. Removing the outer double quotes (which
are unnecessary) is a workaround, but it's still a bug as every
other shell accepts this. This bug has been present since the
original Bourne shell.

src/cmd/ksh93/sh/lex.c: sh_lex(): case S_QUOTE:
- If the current character is '"' and we're in a `...` command
  substitution (ingrave is true), then do not switch to the old
  mode but keep using the ST_QUOTE state table.

Thanks to @JohnoKing for the report and to @atheik for the fix.

Co-authored by: Martijn Dekker <martijn@inlv.org>
Resolves: https://github.com/ksh93/ksh/issues/352
This commit is contained in:
atheik 2022-05-20 22:29:20 +01:00 committed by Martijn Dekker
parent c86713455c
commit 40a5c45b48
4 changed files with 25 additions and 3 deletions

6
NEWS
View file

@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
Any uppercase BUG_* names are modernish shell bug IDs.
2022-05-20:
- Fixed an ancient bug that caused a spurious syntax error when using double
quotes within a `backtick` command substitution within double quotes.
Thanks to atheik for the analysis and the fix.
2022-03-10:
- Fixed another corner case bug in the 'test'/'[' command.

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2022-03-10" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2022-05-20" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -772,9 +772,20 @@ int sh_lex(Lex_t* lp)
{
if(sh.inlineno > lp->lastline)
lp->lex.last_quote = c;
/*
* At this point, we know that the previous skipping of characters was done
* according to the ST_QUOTE state table. We also know that the character that
* stopped the skipping is also the ending character for the current level. If
* that character was " and if we are in a `...` statement, then don't switch
* to the old mode, as we are actually at the innermost section of a "`"..."`"
* statement, which should be skipped again using the ST_QUOTE state table.
*/
if(c!='"' || !ingrave)
{
mode = oldmode(lp);
poplevel(lp);
}
}
else if(c=='"' && n==RBRACE)
mode = ST_QNEST;
break;

View file

@ -290,5 +290,10 @@ got="${var:+'}text between expansions${var:+'}"
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (8)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
# https://github.com/ksh93/ksh/issues/352
got=$(eval 'foo="`: "^Exec(\[[^]=]*])?="`"' 2>&1) || err_exit "Backtick command substitutions can't nest double quotes" \
"(got $(printf %q "$got"))"
# ======
exit $((Errors<125?Errors:125))