dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Youfu Zhang <zhangyoufu@gmail.com>
To: dash@vger.kernel.org
Cc: Youfu Zhang <zhangyoufu@gmail.com>
Subject: [PATCH] [BUILTIN] describe_command: fix incorrect path
Date: Fri, 26 May 2017 15:04:12 +0800	[thread overview]
Message-ID: <20170526070412.19254-1-zhangyoufu@gmail.com> (raw)

$ 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 <zhangyoufu@gmail.com>
---
 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: {
-- 
2.8.4 (Apple Git-73)


             reply	other threads:[~2017-05-26  7:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26  7:04 Youfu Zhang [this message]
2017-05-26  7:59 ` [PATCH] [BUILTIN] describe_command: fix incorrect path Harald van Dijk
2017-05-26 14:47   ` Youfu Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170526070412.19254-1-zhangyoufu@gmail.com \
    --to=zhangyoufu@gmail.com \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).