From nobody Wed Oct 27 19:34:02 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 0BF231813BED; Wed, 27 Oct 2021 19:34:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hff566r2vz3R8C; Wed, 27 Oct 2021 19:34:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CA99715E3D; Wed, 27 Oct 2021 19:34:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19RJY2lY017184; Wed, 27 Oct 2021 19:34:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19RJY2x7017183; Wed, 27 Oct 2021 19:34:02 GMT (envelope-from git) Date: Wed, 27 Oct 2021 19:34:02 GMT Message-Id: <202110271934.19RJY2x7017183@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jilles Tjoelker Subject: git: 72f750dc7c73 - main - sh: Fix heredoc at certain places in case and for List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jilles X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 72f750dc7c7324c3999e4d6cfbb2758694893cdd Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=72f750dc7c7324c3999e4d6cfbb2758694893cdd commit 72f750dc7c7324c3999e4d6cfbb2758694893cdd Author: Jilles Tjoelker AuthorDate: 2021-10-14 20:53:42 +0000 Commit: Jilles Tjoelker CommitDate: 2021-10-27 19:05:19 +0000 sh: Fix heredoc at certain places in case and for After an unescaped newline, there may be a here-document. Some places in case and for did not check for one. Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D32628 --- bin/sh/parser.c | 16 +++++++++------- bin/sh/tests/parser/Makefile | 3 +++ bin/sh/tests/parser/heredoc14.0 | 8 ++++++++ bin/sh/tests/parser/heredoc15.0 | 9 +++++++++ bin/sh/tests/parser/heredoc16.0 | 8 ++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 297d19d4d9b6..e75798800edf 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -480,9 +480,9 @@ command(void) n1 = (union node *)stalloc(sizeof (struct nfor)); n1->type = NFOR; n1->nfor.var = wordtext; - while (readtoken() == TNL) - ; - if (lasttoken == TWORD && ! quoteflag && equal(wordtext, "in")) { + checkkwd = CHKNL; + if (readtoken() == TWORD && !quoteflag && + equal(wordtext, "in")) { app = ≈ while (readtoken() == TWORD) { n2 = makename(); @@ -491,7 +491,9 @@ command(void) } *app = NULL; n1->nfor.args = ap; - if (lasttoken != TNL && lasttoken != TSEMI) + if (lasttoken == TNL) + tokpushback++; + else if (lasttoken != TSEMI) synexpect(-1); } else { static char argvars[5] = { @@ -507,7 +509,7 @@ command(void) * Newline or semicolon here is optional (but note * that the original Bourne shell only allowed NL). */ - if (lasttoken != TNL && lasttoken != TSEMI) + if (lasttoken != TSEMI) tokpushback++; } checkkwd = CHKNL | CHKKWD | CHKALIAS; @@ -526,8 +528,8 @@ command(void) n1->type = NCASE; consumetoken(TWORD); n1->ncase.expr = makename(); - while (readtoken() == TNL); - if (lasttoken != TWORD || ! equal(wordtext, "in")) + checkkwd = CHKNL; + if (readtoken() != TWORD || ! equal(wordtext, "in")) synerror("expecting \"in\""); cpp = &n1->ncase.cases; checkkwd = CHKNL | CHKKWD, readtoken(); diff --git a/bin/sh/tests/parser/Makefile b/bin/sh/tests/parser/Makefile index f3a15badeb52..3239f5bccd84 100644 --- a/bin/sh/tests/parser/Makefile +++ b/bin/sh/tests/parser/Makefile @@ -65,6 +65,9 @@ ${PACKAGE}FILES+= heredoc10.0 ${PACKAGE}FILES+= heredoc11.0 ${PACKAGE}FILES+= heredoc12.0 ${PACKAGE}FILES+= heredoc13.0 +${PACKAGE}FILES+= heredoc14.0 +${PACKAGE}FILES+= heredoc15.0 +${PACKAGE}FILES+= heredoc16.0 ${PACKAGE}FILES+= line-cont1.0 ${PACKAGE}FILES+= line-cont2.0 ${PACKAGE}FILES+= line-cont3.0 diff --git a/bin/sh/tests/parser/heredoc14.0 b/bin/sh/tests/parser/heredoc14.0 new file mode 100644 index 000000000000..036be53dc0c9 --- /dev/null +++ b/bin/sh/tests/parser/heredoc14.0 @@ -0,0 +1,8 @@ +# +read x <