From patchwork Mon May 27 05:39:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10962137 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF9D6933 for ; Mon, 27 May 2019 06:08:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE53428ACB for ; Mon, 27 May 2019 06:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C264828ACE; Mon, 27 May 2019 06:08:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14A9B28ACB for ; Mon, 27 May 2019 06:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725961AbfE0GIA (ORCPT ); Mon, 27 May 2019 02:08:00 -0400 Received: from helcar.hmeau.com ([216.24.177.18]:60886 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725908AbfE0GIA (ORCPT ); Mon, 27 May 2019 02:08:00 -0400 X-Greylist: delayed 1699 seconds by postgrey-1.27 at vger.kernel.org; Mon, 27 May 2019 02:08:00 EDT Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1hV8MG-0004rp-KD; Mon, 27 May 2019 13:39:40 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1hV8MD-0005gc-DG; Mon, 27 May 2019 13:39:37 +0800 Date: Mon, 27 May 2019 13:39:37 +0800 From: Herbert Xu To: Michael Orlitzky Cc: dash@vger.kernel.org Subject: parser: Only accept single-digit parameter expansion outside of braces Message-ID: <20190527053937.s3dmtzec4zo6gpcg@gondor.apana.org.au> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Apr 25, 2019 at 01:39:52AM +0000, Michael Orlitzky wrote: > The POSIX spec says, > > The parameter name or symbol can be enclosed in braces, which are > optional except for positional parameters with more than one digit or > when parameter is a name and is followed by a character that could be > interpreted as part of the name. > > However, dash seems to diverge from that behavior when we get to $10: > > $ cat test.sh > echo $10 > > $ dash ./test.sh one two three four five six seven eight nine ten > ten > > $ bash ./test.sh one two three four five six seven eight nine ten > one0 This patch should fix the problem. Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 1f9e8ec..2f14bf3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1268,7 +1268,7 @@ varname: do { STPUTC(c, out); c = pgetc_eatbnl(); - } while (is_digit(c)); + } while (!subtype && is_digit(c)); } else if (c != '}') { int cc = c;