From patchwork Tue May 26 13:19:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 11570531 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2576513B4 for ; Tue, 26 May 2020 13:19:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B73E2086A for ; Tue, 26 May 2020 13:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726882AbgEZNTN (ORCPT ); Tue, 26 May 2020 09:19:13 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:55652 "EHLO fornost.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726437AbgEZNTN (ORCPT ); Tue, 26 May 2020 09:19:13 -0400 Received: from gwarestrin.arnor.me.apana.org.au ([192.168.0.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1jdZU1-00073i-3U; Tue, 26 May 2020 23:19:06 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Tue, 26 May 2020 23:19:05 +1000 Date: Tue, 26 May 2020 23:19:05 +1000 From: Herbert Xu To: Ron Yorston Cc: dash@vger.kernel.org, dash@mattwhitlock.name Subject: parser: Fix double-backslash nl in old-style command sub Message-ID: <20200526131904.GA27783@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5ec6f94c.cf6OsC6v8fwGBIKX%rmy@frippery.org> X-Newsgroups: apana.lists.os.linux.dash User-Agent: Mutt/1.10.1 (2018-07-13) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org Ron Yorston wrote: > > Alternatively I see that BusyBox ash did this: > > case '\\': > - pc = pgetc(); > - if (pc == '\n') { > - nlprompt(); > - /* > - * If eating a newline, avoid putting > - * the newline into the new character > - * stream (via the STPUTC after the > - * switch). > - */ > - continue; > - } > + pc = pgetc(); /* or pgetc_eatbnl()? why (example)? */ Yes this is the correct fix. ---8<--- When handling backslashes within an old-style command substitution, we should not call pgetc_eatbnl because that would treat the next backslash character as another escape character if it was then followed by a new-line. This patch fixes it by calling pgetc. Reported-by: Matt Whitlock Fixes: 6bbc71d84bea ("parser: use pgetc_eatbnl() in more places") Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 3131045..03c103b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1393,7 +1393,7 @@ parsebackq: { goto done; case '\\': - pc = pgetc_eatbnl(); + pc = pgetc(); if (pc != '\\' && pc != '`' && pc != '$' && (!synstack->dblquote || pc != '"')) STPUTC('\\', pout);