← Commit list

7648dc721

Denys Vlasenko
Denys Vlasenko
2025-08-07
SUCCESS Duration: 171s

Subject

ash,hush: fix corner cases with backslash-newlines in heredocs

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.c+4 -3
@@ -12735,21 +12735,22 @@ checkend: {
if (striptabs) {
while (c == '\t')
- c = pgetc();
+ c = pgetc_eatbnl(); /* dash does pgetc() */
+ /* (see heredoc_bkslash_newline3a.tests) */
}
markloc = out - (char *)stackblock();
for (p = eofmark; STPUTC(c, out), *p; p++) {
if (c != *p)
goto more_heredoc;
- /* FIXME: fails for backslash-newlined terminator:
+ /* dash still has this not fixed (as of 2025-08)
* cat <<EOF
* ...
* EO\
* F
* (see heredoc_bkslash_newline2.tests)
*/
- c = pgetc();
+ c = pgetc_eatbnl(); /* dash does pgetc() */
}
if (c == '\n' || c == PEOF) {
shell/ash_test/ash-heredoc/heredoc_bkslash_newline2a.right+1 -0
@@ -0,0 +1 @@
+Ok1
shell/ash_test/ash-heredoc/heredoc_bkslash_newline2a.tests+4 -0
@@ -0,0 +1,4 @@
+cat <<-EOF
+ Ok1
+ EO\
+F
shell/ash_test/ash-heredoc/heredoc_bkslash_newline3.right+1 -0
@@ -0,0 +1 @@
+Ok1
shell/ash_test/ash-heredoc/heredoc_bkslash_newline3.tests+4 -0
@@ -0,0 +1,4 @@
+cat <<EOF
+Ok1
+\
+EOF
shell/ash_test/ash-heredoc/heredoc_bkslash_newline3a.right+1 -0
@@ -0,0 +1 @@
+Ok1
shell/ash_test/ash-heredoc/heredoc_bkslash_newline3a.tests+4 -0
@@ -0,0 +1,4 @@
+cat <<-EOF
+Ok1
+ \
+ EOF
shell/hush.c+10 -2
@@ -4639,7 +4639,15 @@ static char *fetch_till_str(o_string *as_string,
past_EOL = heredoc.length;
/* Get 1st char of next line, possibly skipping leading tabs */
do {
- ch = i_getch(input);
+ if (heredoc_flags & HEREDOC_QUOTED)
+ ch = i_getch(input);
+ else { /* see heredoc_bkslash_newline3a.tests:
+ * cat <<-EOF
+ * <tab>\
+ * <tab>EOF
+ */
+ ch = i_getch_and_eat_bkslash_nl(input);
+ }
if (ch != EOF)
nommu_addchr(as_string, ch);
} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
@@ -4665,7 +4673,7 @@ static char *fetch_till_str(o_string *as_string,
prev = 0; /* not '\' */
continue;
}
- }
+ } /* if (\n or EOF) */
if (ch == EOF) {
o_free(&heredoc);
return NULL; /* error */
shell/hush_test/hush-heredoc/heredoc_bkslash_newline2a.right+1 -0
@@ -0,0 +1 @@
+Ok1
shell/hush_test/hush-heredoc/heredoc_bkslash_newline2a.tests+4 -0
@@ -0,0 +1,4 @@
+cat <<-EOF
+ Ok1
+ EO\
+F
shell/hush_test/hush-heredoc/heredoc_bkslash_newline3.right+1 -0
@@ -0,0 +1 @@
+Ok1
shell/hush_test/hush-heredoc/heredoc_bkslash_newline3.tests+4 -0
@@ -0,0 +1,4 @@
+cat <<EOF
+Ok1
+\
+EOF
shell/hush_test/hush-heredoc/heredoc_bkslash_newline3a.right+1 -0
@@ -0,0 +1 @@
+Ok1
shell/hush_test/hush-heredoc/heredoc_bkslash_newline3a.tests+4 -0
@@ -0,0 +1,4 @@
+cat <<-EOF
+Ok1
+ \
+ EOF