From c0eb20351d14932c5535789bce0251ab8718df77 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 29 Oct 2015 11:31:39 +0000 Subject: [PATCH] ash: backport fix for here document issues Reported-by: Natanael Copa Signed-off-by: Ron Yorston --- shell/ash.c | 72 +++++++++++++------------------ shell/ash_test/ash-heredoc/heredoc2.right | 2 + shell/ash_test/ash-heredoc/heredoc2.tests | 7 +++ 3 files changed, 39 insertions(+), 42 deletions(-) create mode 100644 shell/ash_test/ash-heredoc/heredoc2.right create mode 100644 shell/ash_test/ash-heredoc/heredoc2.tests diff --git a/shell/ash.c b/shell/ash.c index 8a1628e..f13dd2a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10516,7 +10516,7 @@ static union node *andor(void); static union node *pipeline(void); static union node *parse_command(void); static void parseheredoc(void); -static char nexttoken_ends_list(void); +static int peektoken(void); static int readtoken(void); static union node * @@ -10525,11 +10525,27 @@ list(int nlflag) union node *n1, *n2, *n3; int tok; - checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (nlflag == 2 && nexttoken_ends_list()) - return NULL; n1 = NULL; for (;;) { + switch (peektoken()) { + case TNL: + if (!(nlflag & 1)) + break; + parseheredoc(); + return n1; + + case TEOF: + if (!n1 && (nlflag & 1)) + n1 = NODE_EOF; + parseheredoc(); + return n1; + } + + checkkwd = CHKNL | CHKKWD | CHKALIAS; + if (nlflag == 2 && tokname_array[peektoken()][0]) + return n1; + nlflag |= 2; + n2 = andor(); tok = readtoken(); if (tok == TBACKGND) { @@ -10555,37 +10571,15 @@ list(int nlflag) n1 = n3; } switch (tok) { + case TNL: + case TEOF: + tokpushback = 1; + /* fall through */ case TBACKGND: case TSEMI: - tok = readtoken(); - /* fall through */ - case TNL: - if (tok == TNL) { - parseheredoc(); - if (nlflag == 1) - return n1; - } else { - tokpushback = 1; - } - checkkwd = CHKNL | CHKKWD | CHKALIAS; - if (nexttoken_ends_list()) { - /* Testcase: "<