diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-02-25 17:50:43 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-02-25 17:53:25 +0100 |
commit | 758b21402abc7015cfc54eb21a2e7eead1ecf6ba (patch) | |
tree | dce318909aa47fa4abbb3d9f68fbc64b0c9cd795 | |
parent | 2639f3bc72ac2f03af7ccc825429ccb2fce99a16 (diff) | |
download | busybox-w32-758b21402abc7015cfc54eb21a2e7eead1ecf6ba.tar.gz busybox-w32-758b21402abc7015cfc54eb21a2e7eead1ecf6ba.tar.bz2 busybox-w32-758b21402abc7015cfc54eb21a2e7eead1ecf6ba.zip |
hush: detect when terminating "done"/"fi" is missing
function old new delta
parse_stream 2271 2292 +21
.rodata 105408 105427 +19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0) Total: 40 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash_test/ash-parsing/nodone1.right | 1 | ||||
-rwxr-xr-x | shell/ash_test/ash-parsing/nodone1.tests | 1 | ||||
-rw-r--r-- | shell/ash_test/ash-parsing/nodone2.right | 1 | ||||
-rwxr-xr-x | shell/ash_test/ash-parsing/nodone2.tests | 3 | ||||
-rw-r--r-- | shell/hush.c | 11 | ||||
-rw-r--r-- | shell/hush_test/hush-parsing/nodone1.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-parsing/nodone1.tests | 1 | ||||
-rw-r--r-- | shell/hush_test/hush-parsing/nodone2.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-parsing/nodone2.tests | 3 |
9 files changed, 22 insertions, 1 deletions
diff --git a/shell/ash_test/ash-parsing/nodone1.right b/shell/ash_test/ash-parsing/nodone1.right new file mode 100644 index 000000000..0150ccad5 --- /dev/null +++ b/shell/ash_test/ash-parsing/nodone1.right | |||
@@ -0,0 +1 @@ | |||
./nodone1.tests: line 2: syntax error: unexpected end of file (expecting "done") | |||
diff --git a/shell/ash_test/ash-parsing/nodone1.tests b/shell/ash_test/ash-parsing/nodone1.tests new file mode 100755 index 000000000..de286c5a2 --- /dev/null +++ b/shell/ash_test/ash-parsing/nodone1.tests | |||
@@ -0,0 +1 @@ | |||
for i; do : | |||
diff --git a/shell/ash_test/ash-parsing/nodone2.right b/shell/ash_test/ash-parsing/nodone2.right new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/shell/ash_test/ash-parsing/nodone2.right | |||
@@ -0,0 +1 @@ | |||
1 | |||
diff --git a/shell/ash_test/ash-parsing/nodone2.tests b/shell/ash_test/ash-parsing/nodone2.tests new file mode 100755 index 000000000..69537b3b1 --- /dev/null +++ b/shell/ash_test/ash-parsing/nodone2.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | for i in 1; do echo $i | ||
2 | # the next line has no EOL. It still must count as "done" keyword: | ||
3 | done \ No newline at end of file | ||
diff --git a/shell/hush.c b/shell/hush.c index 0c91008b9..3e6a13b32 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5497,6 +5497,15 @@ static struct pipe *parse_stream(char **pstring, | |||
5497 | } | 5497 | } |
5498 | o_free_and_set_NULL(&ctx.word); | 5498 | o_free_and_set_NULL(&ctx.word); |
5499 | done_pipe(&ctx, PIPE_SEQ); | 5499 | done_pipe(&ctx, PIPE_SEQ); |
5500 | |||
5501 | /* Do we sit inside of any if's, loops or case's? */ | ||
5502 | if (HAS_KEYWORDS | ||
5503 | IF_HAS_KEYWORDS(&& (ctx.ctx_res_w != RES_NONE || ctx.old_flag != 0)) | ||
5504 | ) { | ||
5505 | syntax_error_unterm_str("compound statement"); | ||
5506 | goto parse_error_exitcode1; | ||
5507 | } | ||
5508 | |||
5500 | pi = ctx.list_head; | 5509 | pi = ctx.list_head; |
5501 | /* If we got nothing... */ | 5510 | /* If we got nothing... */ |
5502 | /* (this makes bare "&" cmd a no-op. | 5511 | /* (this makes bare "&" cmd a no-op. |
@@ -5519,7 +5528,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5519 | // *heredoc_cnt_ptr = heredoc_cnt; | 5528 | // *heredoc_cnt_ptr = heredoc_cnt; |
5520 | debug_leave(); | 5529 | debug_leave(); |
5521 | debug_printf_heredoc("parse_stream return heredoc_cnt:%d\n", heredoc_cnt); | 5530 | debug_printf_heredoc("parse_stream return heredoc_cnt:%d\n", heredoc_cnt); |
5522 | debug_printf_parse("parse_stream return %p\n", pi); | 5531 | debug_printf_parse("parse_stream return %p: EOF\n", pi); |
5523 | return pi; | 5532 | return pi; |
5524 | } | 5533 | } |
5525 | 5534 | ||
diff --git a/shell/hush_test/hush-parsing/nodone1.right b/shell/hush_test/hush-parsing/nodone1.right new file mode 100644 index 000000000..3dc1bcfbe --- /dev/null +++ b/shell/hush_test/hush-parsing/nodone1.right | |||
@@ -0,0 +1 @@ | |||
hush: syntax error: unterminated compound statement | |||
diff --git a/shell/hush_test/hush-parsing/nodone1.tests b/shell/hush_test/hush-parsing/nodone1.tests new file mode 100755 index 000000000..de286c5a2 --- /dev/null +++ b/shell/hush_test/hush-parsing/nodone1.tests | |||
@@ -0,0 +1 @@ | |||
for i; do : | |||
diff --git a/shell/hush_test/hush-parsing/nodone2.right b/shell/hush_test/hush-parsing/nodone2.right new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/shell/hush_test/hush-parsing/nodone2.right | |||
@@ -0,0 +1 @@ | |||
1 | |||
diff --git a/shell/hush_test/hush-parsing/nodone2.tests b/shell/hush_test/hush-parsing/nodone2.tests new file mode 100755 index 000000000..69537b3b1 --- /dev/null +++ b/shell/hush_test/hush-parsing/nodone2.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | for i in 1; do echo $i | ||
2 | # the next line has no EOL. It still must count as "done" keyword: | ||
3 | done \ No newline at end of file | ||