From patchwork Fri May 26 07:59:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald van Dijk X-Patchwork-Id: 9749933 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 8371760249 for ; Fri, 26 May 2017 08:10:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F5BB281C3 for ; Fri, 26 May 2017 08:10:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6100D283BF; Fri, 26 May 2017 08:10:34 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 B511D281C3 for ; Fri, 26 May 2017 08:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947289AbdEZIJt (ORCPT ); Fri, 26 May 2017 04:09:49 -0400 Received: from home.gigawatt.nl ([83.163.3.213]:33758 "EHLO home.gigawatt.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163984AbdEZIIa (ORCPT ); Fri, 26 May 2017 04:08:30 -0400 X-Greylist: delayed 522 seconds by postgrey-1.27 at vger.kernel.org; Fri, 26 May 2017 04:08:30 EDT Received: from [IPv6:2001:980:4809:1:2cad:bf57:92dd:44c8] (unknown [IPv6:2001:980:4809:1:2cad:bf57:92dd:44c8]) by home.gigawatt.nl (Postfix) with ESMTPSA id EF8765400067; Fri, 26 May 2017 07:59:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 home.gigawatt.nl EF8765400067 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gigawatt.nl; s=default; t=1495785586; bh=GP509tcGlSDQjAkZfvniOks1OG2O/m87M2qIZQBsahw=; l=1834; h=Subject:To:References:From:Date:In-Reply-To:From; b=lNcE/dFvXUtOWGRiHm9x3VI744SGGqQAviOZGpdoBqCYxuHqwfg3rntfEJkO3H/fs uksdQHvqft4R3xepcx/yzYHy3TRsjxLh9f/9uFtbhSmWz8LpIqcwNJWG5ehQtdySQ9 YOPOL9aNMvpkpk+Z1ZxsR+7hsKXId8rr9608LpUo= Subject: Re: [PATCH] [BUILTIN] describe_command: fix incorrect path To: Youfu Zhang , dash@vger.kernel.org References: <20170526070412.19254-1-zhangyoufu@gmail.com> From: Harald van Dijk Message-ID: Date: Fri, 26 May 2017 09:59:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20170526070412.19254-1-zhangyoufu@gmail.com> Content-Language: en-US Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, On 26/05/17 09:04, Youfu Zhang wrote: > $ 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. True, but only when a path is passed in. If the default path is used, looking up in the hash table is correct, and printing tracked aliases is intentional. If it's desirable to drop that feature, then it should be dropped completely, code shouldn't be left in that can no longer be used. But it's possible to keep it working: how about this instead? Signed-off-by: Harald van Dijk --- src/exec.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) } else { -- 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/exec.c b/src/exec.c index ec0eadd..1350da3 100644 --- a/src/exec.c +++ b/src/exec.c @@ -743,8 +743,6 @@ describe_command(out, command, path, verbose) struct tblentry *cmdp; const struct alias *ap; - path = path ?: pathval(); - if (verbose) { outstr(command, out); } @@ -767,8 +765,15 @@ describe_command(out, command, path, verbose) goto out; } - /* Then check if it is a tracked alias */ - if ((cmdp = cmdlookup(command, 0)) != NULL) { + /* Then if the standard search path is used, check if it is a tracked alias. */ + if (path == NULL) { + path = pathval(); + cmdp = cmdlookup(command, 0); + } else { + cmdp = NULL; + } + + if (cmdp != NULL) { entry.cmdtype = cmdp->cmdtype; entry.u = cmdp->param;