[git commit] hush: fix SEGV on "echo << >" and such
Denys Vlasenko
vda.linux at googlemail.com
Tue Jul 8 08:36:12 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=e9c21c5c3a698468be1daceaad931901e1d63aed
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
.rodata 105787 105823 +36
fetch_heredocs 461 477 +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0) Total: 52 bytes
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
shell/hush.c | 5 +++++
shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.right | 1 +
shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.tests | 2 ++
shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.right | 1 +
shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.tests | 2 ++
5 files changed, 11 insertions(+)
diff --git a/shell/hush.c b/shell/hush.c
index 0b2bc01f5..d1f687f9d 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -4625,6 +4625,11 @@ static int fetch_heredocs(o_string *as_string, struct pipe *pi, int heredoc_cnt,
redir->rd_type = REDIRECT_HEREDOC2;
/* redir->rd_dup is (ab)used to indicate <<- */
+ if (!redir->rd_filename) {
+ /* examples: "echo <<", "echo <<<", "echo <<>" */
+ syntax_error("missing here document terminator");
+ return -1;
+ }
p = fetch_till_str(as_string, input,
redir->rd_filename, redir->rd_dup);
if (!p) {
diff --git a/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.right b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.right
new file mode 100644
index 000000000..7af73557a
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.right
@@ -0,0 +1 @@
+hush: syntax error: missing here document terminator
diff --git a/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.tests b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.tests
new file mode 100755
index 000000000..33ccde26b
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF1.tests
@@ -0,0 +1,2 @@
+echo <<
+echo Done:
diff --git a/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.right b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.right
new file mode 100644
index 000000000..7af73557a
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.right
@@ -0,0 +1 @@
+hush: syntax error: missing here document terminator
diff --git a/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.tests b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.tests
new file mode 100755
index 000000000..fcda11045
--- /dev/null
+++ b/shell/hush_test/hush-heredoc/heredoc_syntax_err_no_EOF2.tests
@@ -0,0 +1,2 @@
+echo << >
+echo Done:
More information about the busybox-cvs
mailing list