Skip to content
Snippets Groups Projects
Commit f19f3b39 authored by Harald van Dijk's avatar Harald van Dijk Committed by Herbert Xu
Browse files

builtin: describe_command - fix incorrect path


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: default avatarHarald van Dijk <harald@gigawatt.nl>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 53dab360
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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);
}
Loading
Loading
@@ -767,8 +765,17 @@ 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;
} else {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment