diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-11 12:39:18 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-11 12:39:18 +0200 |
commit | 680c3016a2dddc3edb4d79868a728e899638e2c4 (patch) | |
tree | 6897bbd14235c8d2f424ce60a1b8e428961a9c4b /shell | |
parent | 0403bedccc17c8ea3059523e32ea615e5df4bc26 (diff) | |
download | busybox-w32-680c3016a2dddc3edb4d79868a728e899638e2c4.tar.gz busybox-w32-680c3016a2dddc3edb4d79868a728e899638e2c4.tar.bz2 busybox-w32-680c3016a2dddc3edb4d79868a728e899638e2c4.zip |
ash: parser: Allow newlines within parameter substitution
Upstream commit:
Date: Thu, 22 Mar 2018 21:41:24 +0800
parser: Allow newlines within parameter substitution
On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote:
> On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote:
> >
> > Okay, it can be trivially modified to something that does work in other
> > shells (even if it were actually executed), but gets rejected at parse time
> > by dash:
> >
> > if false; then
> > : ${$+
> > }
> > fi
>
> That's just a bug in dash's parser with ${} in general, because
> it bombs out without the if clause too:
>
> : ${$+
> }
This patch fixes the parsing of newlines with parameter substitution.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 5 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/param_expand_alt2.right | 4 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/param_expand_alt2.tests | 7 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/param_expand_alt2.right | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_alt2.tests | 7 |
5 files changed, 26 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index 6f8bc9042..40ca82d0b 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -11999,8 +11999,11 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11999 | CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */ | 11999 | CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */ |
12000 | switch (SIT(c, synstack->syntax)) { | 12000 | switch (SIT(c, synstack->syntax)) { |
12001 | case CNL: /* '\n' */ | 12001 | case CNL: /* '\n' */ |
12002 | if (synstack->syntax == BASESYNTAX) | 12002 | if (synstack->syntax == BASESYNTAX |
12003 | && !synstack->varnest | ||
12004 | ) { | ||
12003 | goto endword; /* exit outer loop */ | 12005 | goto endword; /* exit outer loop */ |
12006 | } | ||
12004 | USTPUTC(c, out); | 12007 | USTPUTC(c, out); |
12005 | nlprompt(); | 12008 | nlprompt(); |
12006 | c = pgetc(); | 12009 | c = pgetc(); |
diff --git a/shell/ash_test/ash-vars/param_expand_alt2.right b/shell/ash_test/ash-vars/param_expand_alt2.right new file mode 100644 index 000000000..fef5889ca --- /dev/null +++ b/shell/ash_test/ash-vars/param_expand_alt2.right | |||
@@ -0,0 +1,4 @@ | |||
1 | Unquoted: H H | ||
2 | Quoted: H | ||
3 | H | ||
4 | Ok:0 | ||
diff --git a/shell/ash_test/ash-vars/param_expand_alt2.tests b/shell/ash_test/ash-vars/param_expand_alt2.tests new file mode 100755 index 000000000..d8abf4c3b --- /dev/null +++ b/shell/ash_test/ash-vars/param_expand_alt2.tests | |||
@@ -0,0 +1,7 @@ | |||
1 | echo Unquoted: H${$+ | ||
2 | }H | ||
3 | |||
4 | echo Quoted: "H${$+ | ||
5 | }H" | ||
6 | |||
7 | echo Ok:$? | ||
diff --git a/shell/hush_test/hush-vars/param_expand_alt2.right b/shell/hush_test/hush-vars/param_expand_alt2.right new file mode 100644 index 000000000..fef5889ca --- /dev/null +++ b/shell/hush_test/hush-vars/param_expand_alt2.right | |||
@@ -0,0 +1,4 @@ | |||
1 | Unquoted: H H | ||
2 | Quoted: H | ||
3 | H | ||
4 | Ok:0 | ||
diff --git a/shell/hush_test/hush-vars/param_expand_alt2.tests b/shell/hush_test/hush-vars/param_expand_alt2.tests new file mode 100755 index 000000000..d8abf4c3b --- /dev/null +++ b/shell/hush_test/hush-vars/param_expand_alt2.tests | |||
@@ -0,0 +1,7 @@ | |||
1 | echo Unquoted: H${$+ | ||
2 | }H | ||
3 | |||
4 | echo Quoted: "H${$+ | ||
5 | }H" | ||
6 | |||
7 | echo Ok:$? | ||