diff mbox series

parser: Fix double-backslash nl in old-style command sub

Message ID 20200526131904.GA27783@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series parser: Fix double-backslash nl in old-style command sub | expand

Commit Message

Herbert Xu May 26, 2020, 1:19 p.m. UTC
Ron Yorston <rmy@frippery.org> wrote:
>
> Alternatively I see that BusyBox ash did this:
> 
>            case '\\':
> -               pc = pgetc();
> -               if (pc == '\n') {
> -                   nlprompt();
> -                   /*
> -                    * If eating a newline, avoid putting
> -                    * the newline into the new character
> -                    * stream (via the STPUTC after the
> -                    * switch).
> -                    */
> -                   continue;
> -               }
> +               pc = pgetc(); /* or pgetc_eatbnl()? why (example)? */

Yes this is the correct fix.

---8<---
When handling backslashes within an old-style command substitution,
we should not call pgetc_eatbnl because that would treat the next
backslash character as another escape character if it was then
followed by a new-line.

This patch fixes it by calling pgetc.

Reported-by: Matt Whitlock <dash@mattwhitlock.name>
Fixes: 6bbc71d84bea ("parser: use pgetc_eatbnl() in more places")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff mbox series

Patch

diff --git a/src/parser.c b/src/parser.c
index 3131045..03c103b 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1393,7 +1393,7 @@  parsebackq: {
 				goto done;
 
 			case '\\':
-                                pc = pgetc_eatbnl();
+                                pc = pgetc();
                                 if (pc != '\\' && pc != '`' && pc != '$'
                                     && (!synstack->dblquote || pc != '"'))
                                         STPUTC('\\', pout);