From patchwork Tue Mar 6 17:40:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martijn Dekker X-Patchwork-Id: 10262327 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.web.codeaurora.org (Postfix) with ESMTP id 6257F6016D for ; Tue, 6 Mar 2018 17:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5304F29120 for ; Tue, 6 Mar 2018 17:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 476BB2911C; Tue, 6 Mar 2018 17:40:38 +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=-6.9 required=2.0 tests=BAYES_00,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 DA850290DD for ; Tue, 6 Mar 2018 17:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753891AbeCFRkh (ORCPT ); Tue, 6 Mar 2018 12:40:37 -0500 Received: from kahlil.inlv.org ([37.59.109.123]:37950 "EHLO kahlil.inlv.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753890AbeCFRkg (ORCPT ); Tue, 6 Mar 2018 12:40:36 -0500 Received: from [192.168.1.81] (host86-129-6-191.range86-129.btcentralplus.com [86.129.6.191]) (authenticated bits=0) by kahlil.inlv.org (8.14.9/8.14.4) with ESMTP id w26HeZiT022147 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Tue, 6 Mar 2018 18:40:35 +0100 Subject: [PATCH] 'nolog' and 'debug' options cause "$-" to wreak havoc From: Martijn Dekker To: dash@vger.kernel.org References: <5bdf99b4-2bde-3710-c323-25162ace143f@inlv.org> Message-ID: <20708080-c91c-4f02-3198-bfcc6963ebe9@inlv.org> Date: Tue, 6 Mar 2018 17:40:37 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <5bdf99b4-2bde-3710-c323-25162ace143f@inlv.org> Content-Language: en-GB Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Op 29-03-17 om 20:02 schreef Martijn Dekker: > Bug: if either the 'nolog' or the 'debug' option is set, trying to > expand "$-" silently aborts parsing of an entire argument. > > $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; \ > set +o nolog; echo "|$- are the options|"' > | > |uCf are the options| > $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; \ > set +o debug; echo "|$- are the options|"' > | > |uCf are the options| This turned out to be easy to fix. The routine producing the "$-" expansion failed to skip options for which there is no option letter, but only a long-form name. In dash, 'nolog' and 'debug' are currently the only two such options. Patch below. - Martijn --- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/expand.c b/src/expand.c index 2a50830..71a0031 100644 --- a/src/expand.c +++ b/src/expand.c @@ -925,7 +925,7 @@ numvar: case '-': p = makestrspace(NOPTS, expdest); for (i = NOPTS - 1; i >= 0; i--) { - if (optlist[i]) { + if (optlist[i] && optletters[i]) { USTPUTC(optletters[i], p); len++; }