← Commit list

758b21402

Denys Vlasenko
Denys Vlasenko
2024-02-25
SUCCESS Duration: 155s

Subject

hush: detect when terminating "done"/"fi" is missing

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/ash_test/ash-parsing/nodone1.right+1 -0
@@ -0,0 +1 @@
+./nodone1.tests: line 2: syntax error: unexpected end of file (expecting "done")
shell/ash_test/ash-parsing/nodone1.tests+1 -0
@@ -0,0 +1 @@
+for i; do :
shell/ash_test/ash-parsing/nodone2.right+1 -0
@@ -0,0 +1 @@
+1
shell/ash_test/ash-parsing/nodone2.tests+3 -0
@@ -0,0 +1,3 @@
+for i in 1; do echo $i
+# the next line has no EOL. It still must count as "done" keyword:
+done
shell/hush.c+10 -1
@@ -5497,6 +5497,15 @@ static struct pipe *parse_stream(char **pstring,
}
o_free_and_set_NULL(&ctx.word);
done_pipe(&ctx, PIPE_SEQ);
+
+ /* Do we sit inside of any if's, loops or case's? */
+ if (HAS_KEYWORDS
+ IF_HAS_KEYWORDS(&& (ctx.ctx_res_w != RES_NONE || ctx.old_flag != 0))
+ ) {
+ syntax_error_unterm_str("compound statement");
+ goto parse_error_exitcode1;
+ }
+
pi = ctx.list_head;
/* If we got nothing... */
/* (this makes bare "&" cmd a no-op.
@@ -5519,7 +5528,7 @@ static struct pipe *parse_stream(char **pstring,
// *heredoc_cnt_ptr = heredoc_cnt;
debug_leave();
debug_printf_heredoc("parse_stream return heredoc_cnt:%d\n", heredoc_cnt);
- debug_printf_parse("parse_stream return %p\n", pi);
+ debug_printf_parse("parse_stream return %p: EOF\n", pi);
return pi;
}
shell/hush_test/hush-parsing/nodone1.right+1 -0
@@ -0,0 +1 @@
+hush: syntax error: unterminated compound statement
shell/hush_test/hush-parsing/nodone1.tests+1 -0
@@ -0,0 +1 @@
+for i; do :
shell/hush_test/hush-parsing/nodone2.right+1 -0
@@ -0,0 +1 @@
+1
shell/hush_test/hush-parsing/nodone2.tests+3 -0
@@ -0,0 +1,3 @@
+for i in 1; do echo $i
+# the next line has no EOL. It still must count as "done" keyword:
+done