Re: dash bug: double-quoted "\" breaks glob protection for next char

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 13/02/2018 14:53, Denys Vlasenko wrote:
$ >'\zzzz'
$ >'\wwww'
$ dash -c 'echo "\*"'
\wwww \zzzz

Nice catch.

The cause: uses "\\*" pattern instead of "\\\*".
The fix:

                         /* backslash */
                         case CBACK:
                                 c = pgetc2();
                                 if (c == PEOF) {
                                         USTPUTC(CTLESC, out);
                                         USTPUTC('\\', out);
                                         pungetc();
                                 } else if (c == '\n') {
                                         nlprompt();
                                 } else {
                                         if (
                                                 dblquote &&
                                                 c != '\\' && c != '`' &&
                                                 c != '$' && (
                                                         c != '"' ||
                                                         eofmark != NULL
                                                 )
                                         ) {
USTPUTC(CTLESC, out); // add this line
                                                 USTPUTC('\\', out);
                                         }
                                         USTPUTC(CTLESC, out);
                                         USTPUTC(c, out);
                                         quotef++;
                                 }

I don't think this is right. The bug was introduced in


<https://git.kernel.org/pub/scm/utils/dash/dash.git/commit/?id=7cfd8be0dc83342b4a71f3a8e5b7efab4670e50c>

Prior to that, the line USTPUTC(CTLESC, out); was there. The commit message is saying that the logic for detecting whether \ should be taken literally doesn't belong in the parser, that the parser will get it wrong. The example in the commit message doesn't break with your patch, but short modifications to that example do make it fail:

Currently:

$ dash -c 'foo=a; echo "<${foo#[a\]]}>"'
<>

This is what I expect, and also what bash, ksh and posh do.

With your patch:

$ dash -c 'foo=a; echo "<${foo#[a\]]}>"'
<a>

Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux