From patchwork Fri May 26 07:04:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youfu Zhang X-Patchwork-Id: 9749791 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 4136D60246 for ; Fri, 26 May 2017 07:04:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E18E2624B for ; Fri, 26 May 2017 07:04:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22301283BB; Fri, 26 May 2017 07:04: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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 13FCB2624B for ; Fri, 26 May 2017 07:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947106AbdEZHEt (ORCPT ); Fri, 26 May 2017 03:04:49 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36576 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163817AbdEZHEZ (ORCPT ); Fri, 26 May 2017 03:04:25 -0400 Received: by mail-pf0-f196.google.com with SMTP id n23so788595pfb.3 for ; Fri, 26 May 2017 00:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=cC4qEOljT0LsKSrBmF4KR2Vs4c7Jf4kSYjp/Zqdz+Kk=; b=QucCWFDHcayGuRTrYus27PS7luqGGVy0WACnSnB1lQ3PjTK3LGPpbOgPlPr4fUvmBo clemoNxu0K71ZY+pAfSCsfPSqiGd7tsD4UFViPryLx2xoIMIaiyxWfq+HZSWPVEAEC5E XU8Hnk3UGDPjX4ul9uVC8/eMgWjeyl7byqWYEkOk5b3J66wUFoHTeekUaVJy4HPg7usK is8GgCyuffPaxUrpRI161rBriEDfd9UX46crH6T35Dr40tug3TnS8bHyp0cPMaNGO9aM 4evnY0oAQEQe/vbyH5G7HYudCrFaXi/OL/ZFYbP5N+hj4jXcOZypR4461s1d+yPruhKU vL/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cC4qEOljT0LsKSrBmF4KR2Vs4c7Jf4kSYjp/Zqdz+Kk=; b=uXZgtGGGo9d9KX84DPeRFNOmdwWFaapFF1F3UPOJW3Yhsx/MvJZh/XmarVkH89HtqW 3Yeh/1gMvPa5KYOmecZSUeVn37QKhpgdGM35fIRD/RyrU4IWdXBHYCasgnl1esaLxePe g6n9TfjO4NE9AfhAqEG8p0m4pAPdUYdgkn5d7gErYRuRuZDqdJoyrQWypkyiK7qfilsl aOorn+zHxGukchSnpv2wtKDO8TeBibEXbsnGOcz5NhGa0EfAcsBnEC6DjmGkBR1MlcgV VajU2O9L0dLO0D+zRKmZVlRlA0TCxQVC5Jc1mrQhNMigAbI9HUFCLWmjZ0qZxz9uGjU6 vsnw== X-Gm-Message-State: AODbwcCWzaQS/dRhSwOCF1V5QfBbC33noHvHJeHoIg/i9d7AarraNlRO H5ai8+rhka8TtopQqhA= X-Received: by 10.98.19.206 with SMTP id 75mr591562pft.208.1495782264196; Fri, 26 May 2017 00:04:24 -0700 (PDT) Received: from localhost.in.chaitin.com.com (ec2-54-222-157-178.cn-north-1.compute.amazonaws.com.cn. [54.222.157.178]) by smtp.gmail.com with ESMTPSA id 128sm23666831pgi.49.2017.05.26.00.04.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 May 2017 00:04:22 -0700 (PDT) From: Youfu Zhang To: dash@vger.kernel.org Cc: Youfu Zhang Subject: [PATCH] [BUILTIN] describe_command: fix incorrect path Date: Fri, 26 May 2017 15:04:12 +0800 Message-Id: <20170526070412.19254-1-zhangyoufu@gmail.com> X-Mailer: git-send-email 2.8.4 (Apple Git-73) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP $ PATH=/extra/path:/usr/sbin:/usr/bin:/sbin:/bin \ > sh -xc 'command -V ls; command -V ls; command -Vp ls; command -vp ls' + command -V ls ls is /bin/ls + command -V ls ls is a tracked alias for /bin/ls + command -Vp ls ls is a tracked alias for (null) + command -vp ls Segmentation fault (core dumped) describe_command should respect `path' argument. Looking up in the hash table may gives incorrect index in entry.u.index and finally causes incorrect output or SIGSEGV. Signed-off-by: Youfu Zhang --- src/exec.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/exec.c b/src/exec.c index ec0eadd..c4eeb58 100644 --- a/src/exec.c +++ b/src/exec.c @@ -767,14 +767,8 @@ describe_command(out, command, path, verbose) goto out; } - /* Then check if it is a tracked alias */ - if ((cmdp = cmdlookup(command, 0)) != NULL) { - entry.cmdtype = cmdp->cmdtype; - entry.u = cmdp->param; - } else { - /* Finally use brute force */ - find_command(command, &entry, DO_ABS, path); - } + /* Brute force */ + find_command(command, &entry, DO_ABS, path); switch (entry.cmdtype) { case CMDNORMAL: {