From patchwork Thu May 9 15:46:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Greenberg X-Patchwork-Id: 10937303 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 A58681515 for ; Thu, 9 May 2019 15:46:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 957B2283C3 for ; Thu, 9 May 2019 15:46:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8996B28877; Thu, 9 May 2019 15:46:51 +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,DKIM_SIGNED, DKIM_VALID,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 79618283C3 for ; Thu, 9 May 2019 15:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726561AbfEIPqr (ORCPT ); Thu, 9 May 2019 11:46:47 -0400 Received: from mail-eopbgr720044.outbound.protection.outlook.com ([40.107.72.44]:15168 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726558AbfEIPqq (ORCPT ); Thu, 9 May 2019 11:46:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mymailpomona.onmicrosoft.com; s=selector1-pomona-edu; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bv/OCqz+a4ol5BXcSlBCzyD6T+GR3RZhSdY6wuuqYIU=; b=SKekkoMA4S7mRAAdsEdnFWIb8Y58WXbDd84OobB5HhB2YuwiABeYB+IT49onazdQw5Tbqcy9csfBW0DiWxXC1QvTmibZTJWiiHeEi7rBd9+tLvMpeVDRiX1i6KQAvscxOu0Q4Oozbbd3ZarFYH3cZMM57FwIISrMHVFfv7CeueE= Received: from CY4PR03MB3080.namprd03.prod.outlook.com (10.171.245.145) by CY4PR03MB3285.namprd03.prod.outlook.com (10.171.246.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.12; Thu, 9 May 2019 15:46:43 +0000 Received: from CY4PR03MB3080.namprd03.prod.outlook.com ([fe80::2467:2df9:4e42:c760]) by CY4PR03MB3080.namprd03.prod.outlook.com ([fe80::2467:2df9:4e42:c760%4]) with mapi id 15.20.1856.012; Thu, 9 May 2019 15:46:43 +0000 From: Michael Greenberg To: "dash@vger.kernel.org" Subject: [PATCH] alias: Fix handling of empty aliases Thread-Topic: [PATCH] alias: Fix handling of empty aliases Thread-Index: AQHVBn5m4J2bXFs9vkGiP9ki0qUvOA== Date: Thu, 9 May 2019 15:46:43 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR1201CA0005.namprd12.prod.outlook.com (2603:10b6:405:4c::15) To CY4PR03MB3080.namprd03.prod.outlook.com (2603:10b6:910:53::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Michael.Greenberg@pomona.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [73.68.184.48] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 48f54b02-39cd-49be-5236-08d6d49588c1 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328)(7193020);SRVR:CY4PR03MB3285; x-ms-traffictypediagnostic: CY4PR03MB3285: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-forefront-prvs: 003245E729 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(39850400004)(376002)(346002)(396003)(366004)(189003)(199004)(66066001)(476003)(52116002)(256004)(36756003)(5660300002)(68736007)(4744005)(305945005)(2616005)(102836004)(486006)(25786009)(71200400001)(6512007)(71190400001)(5640700003)(66946007)(53936002)(66556008)(99286004)(72206003)(6486002)(66476007)(64756008)(66446008)(7736002)(73956011)(6436002)(2351001)(44832011)(14454004)(81166006)(6116002)(81156014)(1730700003)(75432002)(186003)(3846002)(26005)(316002)(86362001)(386003)(6506007)(8676002)(478600001)(786003)(2906002)(8936002)(88552002)(6916009)(2501003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR03MB3285;H:CY4PR03MB3080.namprd03.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: pomona.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: pVOdEYRP6nwTow5uC9He6h63XbKiWfWpXNuOwVr00pXmfGwMmFeqoofNyg5KjTaBytfEa/pCvKpVGkXltfKszPFUJrNRH5WgjkvtF9nEv4EXuu7J3YtuD0wajaJlZ7MQA+T4CRWE2EfJDAE4O575iiYNLuaoEBmtpdPbSMy+XCE+f6Z9sRfRN/vfZ8+0PXYmdegZwOjRzDE56U3YivWoQH7Z0A+SA5WxqMq3IeLv7MsxiL9u5TiGG1REa1ZW6aXu88NwGz3QfyvNvIAsYSVuZnMKVyZSD5M0Q6MsPAnEFXGetqdn960FU9sFbbKI1qjSG+SK1a50Xs3pJUX/kXgG2WvJ0fmuzLB7GwU9y8y8ggU86siYO0LjqAHTfouxDDr/7usRt37iLT8E3nw4OwZcVqhwhNBw6RkuIB5ppNzzoB0= MIME-Version: 1.0 X-OriginatorOrg: pomona.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 48f54b02-39cd-49be-5236-08d6d49588c1 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 May 2019 15:46:43.2302 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 817f5904-3904-4ee8-b3a5-a65d4746ff70 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB3285 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Dash was incorrectly handling empty aliases. When attempting to use an empty alias with nothing else, I'm (incorrectly) prompted for more input: ``` $ alias empty='' $ empty > ``` Other shells (e.g., bash, yash) correctly handle the lone, empty alias as an empty command: ``` $ alias empty='' $ empty $ ``` This patch fixes the parser to handle the case where an alias is empty, i.e., produces no token. Signed-off-by: Michael Greenberg diff --git a/src/parser.c b/src/parser.c index 1f9e8ec..a1d6116 100644 --- a/src/parser.c +++ b/src/parser.c @@ -470,6 +470,7 @@ next_case: break; case TWORD: case TREDIR: + case TNL: /* necessary for empty aliases */ tokpushback++; return simplecmd(); } @@ -717,6 +718,7 @@ top: } } +ignorenl: /* empty alias? */ if (t != TWORD || quoteflag) { goto out; } @@ -739,8 +741,11 @@ top: if ((ap = lookupalias(wordtext, 1)) != NULL) { if (*ap->val) { pushstring(ap->val, ap); + goto top; + } else { + t = xxreadtoken(); + goto ignorenl; } - goto top; } } out: