ash: fix incorrect path in describe_command
$ PATH=/extra/path:/usr/sbin:/usr/bin:/sbin:/bin \ > busybox 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 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. function old new delta describe_command 386 313 -73 Signed-off-by: Youfu Zhang <zhangyoufu@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2599937c4e
commit
6683d1cbb4
14
shell/ash.c
14
shell/ash.c
@ -8163,7 +8163,6 @@ static int
|
|||||||
describe_command(char *command, const char *path, int describe_command_verbose)
|
describe_command(char *command, const char *path, int describe_command_verbose)
|
||||||
{
|
{
|
||||||
struct cmdentry entry;
|
struct cmdentry entry;
|
||||||
struct tblentry *cmdp;
|
|
||||||
#if ENABLE_ASH_ALIAS
|
#if ENABLE_ASH_ALIAS
|
||||||
const struct alias *ap;
|
const struct alias *ap;
|
||||||
#endif
|
#endif
|
||||||
@ -8193,15 +8192,8 @@ describe_command(char *command, const char *path, int describe_command_verbose)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Then check if it is a tracked alias */
|
/* Brute force */
|
||||||
cmdp = cmdlookup(command, 0);
|
|
||||||
if (cmdp != NULL) {
|
|
||||||
entry.cmdtype = cmdp->cmdtype;
|
|
||||||
entry.u = cmdp->param;
|
|
||||||
} else {
|
|
||||||
/* Finally use brute force */
|
|
||||||
find_command(command, &entry, DO_ABS, path);
|
find_command(command, &entry, DO_ABS, path);
|
||||||
}
|
|
||||||
|
|
||||||
switch (entry.cmdtype) {
|
switch (entry.cmdtype) {
|
||||||
case CMDNORMAL: {
|
case CMDNORMAL: {
|
||||||
@ -8216,9 +8208,7 @@ describe_command(char *command, const char *path, int describe_command_verbose)
|
|||||||
} while (--j >= 0);
|
} while (--j >= 0);
|
||||||
}
|
}
|
||||||
if (describe_command_verbose) {
|
if (describe_command_verbose) {
|
||||||
out1fmt(" is%s %s",
|
out1fmt(" is %s", p);
|
||||||
(cmdp ? " a tracked alias for" : nullstr), p
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
out1str(p);
|
out1str(p);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user