From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1195 invoked from network); 22 May 2020 21:48:53 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 22 May 2020 21:48:53 -0000 Received: (qmail 20905 invoked by alias); 22 May 2020 21:48:38 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45896 Received: (qmail 1244 invoked by uid 1010); 22 May 2020 21:48:38 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-10.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25814. spamassassin: 3.4.4. Clear:RC:0(80.0.253.74):SA:0(-2.0/5.0):. Processed in 2.376227 secs); 22 May 2020 21:48:38 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.74 as permitted sender) X-Originating-IP: [86.16.88.158] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.3 cv=YvshubQX c=1 sm=1 tr=0 a=MiHCjVqLJ44lE3bxSlffFQ==:117 a=MiHCjVqLJ44lE3bxSlffFQ==:17 a=IkcTkHD0fZMA:10 a=npldXguGAAAA:8 a=Ft-ltLhk0Yiqj1921cgA:9 a=QEXdDO2ut3YA:10 a=1Z6EAcxPEhoA:10 a=Y6yEfkeh0FwA:10 a=1MEZn5qd6kv58cYvHi58:22 Message-ID: <70e0d7c11f064b4f52354e20fba6541cb25d89d9.camel@ntlworld.com> Subject: Re: [BUG] Two vulnerabilities in zsh From: Peter Stephenson To: zsh-workers@zsh.org Date: Fri, 22 May 2020 22:47:58 +0100 In-Reply-To: References: <20200519170418.5bc00b2f@tarpaulin.shahaf.local2> <20200520004509.741352d3@tarpaulin.shahaf.local2> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfOSxdxuj6RcPvrC9YW2AEaSdeX9UjQ85R5VgXvJokk9A5YJTRRVTmE8NqGXtTfKA2kvP29RHnIFAi8JX0l+2zGwoIE2M6pAaipIC8S4wXW21brAYc4K1 GU7HOmO27M4aDCfYR4OIrRuyqRHS5jRpbRl64QCzDMluK4rJMFFlyg50 On Fri, 2020-05-22 at 19:56 +0100, Peter Stephenson wrote: > On Wed, 2020-05-20 at 00:45 +0000, Daniel Shahaf wrote: > > Peter Stephenson wrote on Tue, 19 May 2020 21:38 +0100: > > > The BUG message simplifies to this: > > > > > > (127)9:32% zsh -fc '$\ > > > (' > > > 1: BUG: parse error in command substitution > > > zsh:1: no such file or directory: pws/. > > > > > > The other output shows it's doing something it shouldn't even if there > > > isn't a crash as a result. Adding a command in front does produce a > > > crash. > > > > > > I think the backslashed newline is valid, and it looks like it's usually > > > correctly handled; apparently its presence is disguising the bad input > > > in this case. > > > > Test cases: > > This seems to be doing the right thing. Enhanced version: this handles the bizarre but valid echo $(\ (3+2)) and adds a few tests for cases without a parse error. pws diff --git a/Src/lex.c b/Src/lex.c index a541defe6..9d29c1bc1 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -541,6 +541,16 @@ cmd_or_math_sub(void) { int c = hgetc(), ret; + if (c == '\\') { + c = hgetc(); + if (c != '\n') { + hungetc(c); + hungetc('\\'); + return skipcomm() ? CMD_OR_MATH_ERR : CMD_OR_MATH_CMD; + } + c = hgetc(); + } + if (c == '(') { int lexpos = (int)(lexbuf.ptr - tokstr); add(Inpar); @@ -1237,6 +1247,19 @@ gettokstr(int c, int sub) case LX2_BKSLASH: c = hgetc(); if (c == '\n') { + if (lexbuf.len && !lexstop && + (lexbuf.ptr[-1] == String || + lexbuf.ptr[-1] == Qstring)) + { + /* + * $-prefixed expression interrupted by \\\n. + * This is valid --- reparse. + */ + --lexbuf.len; + --lexbuf.ptr; + c = '$'; + continue; + } c = hgetc(); if (!lexstop) continue; diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 6d2dd0d99..b0b53c7d0 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -2662,7 +2662,25 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888 -f:regression test for workers/45843#1 ?(eval):1: bad substitution -# Temporarily using the 'D' flag because it generates a "BUG:" message in -# debug builds only. $ZTST_testdir/../Src/zsh -fc $'$\\\n(' -1Df:regression test for workers/45843#2: escaped newline in command substitution start token +1f:regression test for workers/45843#2: escaped newline in command substitution start token +?(eval):1: parse error near `$(' + +# ` + + eval $'echo $\\\n(printf "%d\\n" $(( 4 + 2 )) )' +0:Normal command substitution with escaped newline +>6 + + eval $'echo $\\\n(( 14 / 2 ))' +0:Normal math eval with escaped newline after $ +>7 + + eval $'echo $(\\\n( 15 / 3 ))' +0:Normal math eval with escaped newline after $( +>5 + + function '*' { echo What a star; } + eval 'echo $(\*)' +0:Backslash character other than newline is normal after $( +>What a star