From patchwork Mon Feb 25 06:00:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10828257 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 33DFD1575 for ; Mon, 25 Feb 2019 06:00:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 134352AAB7 for ; Mon, 25 Feb 2019 06:00:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00A232AAC0; Mon, 25 Feb 2019 06:00:35 +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 6A6FB2AAB7 for ; Mon, 25 Feb 2019 06:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbfBYGAf (ORCPT ); Mon, 25 Feb 2019 01:00:35 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:44912 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbfBYGAe (ORCPT ); Mon, 25 Feb 2019 01:00:34 -0500 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 1gy9JZ-0000VM-6h; Mon, 25 Feb 2019 14:00:33 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gy9JX-0002Nm-RD; Mon, 25 Feb 2019 14:00:31 +0800 Date: Mon, 25 Feb 2019 14:00:31 +0800 From: Herbert Xu To: Martijn Dekker Cc: DASH shell mailing list Subject: [PATCH] expand: Fix double-decrement in argstr Message-ID: <20190225060031.x5ckegfrskba6zrc@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 Sat, Feb 16, 2019 at 10:26:23PM +0000, Martijn Dekker wrote: > For unset foo: > > dash-git > $ src/dash -c 'set -- ${foo- bar }; echo "[$1]"' > [bar ] > > Release versions of dash and all other shells output: > [bar] > > The change in behaviour appears to have been introduced by commit > 3cd5386 ("expand: Do not reprocess data when expanding words"). Thanks for catching this! ---8<--- Due to a double decrement in argstr we may miss field separators at the end of a word in certain situations. Reported-by: Martijn Dekker Fixes: 3cd538634f71 ("expand: Do not reprocess data when...") Signed-off-by: Herbert Xu diff --git a/src/expand.c b/src/expand.c index af9cac9..e57efa6 100644 --- a/src/expand.c +++ b/src/expand.c @@ -285,7 +285,7 @@ start: q = stnputs(p, length, expdest); q[-1] &= end - 1; expdest = q - (flag & EXP_WORD ? end : 0); - newloc = expdest - (char *)stackblock() - end; + newloc = q - (char *)stackblock() - end; if (breakall && !inquotes && newloc > startloc) { recordregion(startloc, newloc, 0); }