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

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

 



Ron Yorston <rmy@xxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxx>
Fixes: 6bbc71d84bea ("parser: use pgetc_eatbnl() in more places")
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

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);
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



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

  Powered by Linux