aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoufu Zhang <zhangyoufu@gmail.com>2017-05-26 15:31:29 +0800
committerDenys Vlasenko <vda.linux@googlemail.com>2017-05-26 17:37:35 +0200
commit6683d1cbb44859f549f87f882545b84b9369585c (patch)
treea151695f4874f5bb8e2c23ef9b6f2fd4c744b62d
parent2599937c4e5012d8e410d58574d22dec92e6eaa5 (diff)
downloadbusybox-w32-6683d1cbb44859f549f87f882545b84b9369585c.tar.gz
busybox-w32-6683d1cbb44859f549f87f882545b84b9369585c.tar.bz2
busybox-w32-6683d1cbb44859f549f87f882545b84b9369585c.zip
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>
-rw-r--r--shell/ash.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 60c8ffeb7..eb51d47cc 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -8163,7 +8163,6 @@ static int
8163describe_command(char *command, const char *path, int describe_command_verbose) 8163describe_command(char *command, const char *path, int describe_command_verbose)
8164{ 8164{
8165 struct cmdentry entry; 8165 struct cmdentry entry;
8166 struct tblentry *cmdp;
8167#if ENABLE_ASH_ALIAS 8166#if ENABLE_ASH_ALIAS
8168 const struct alias *ap; 8167 const struct alias *ap;
8169#endif 8168#endif
@@ -8193,15 +8192,8 @@ describe_command(char *command, const char *path, int describe_command_verbose)
8193 goto out; 8192 goto out;
8194 } 8193 }
8195#endif 8194#endif
8196 /* Then check if it is a tracked alias */ 8195 /* Brute force */
8197 cmdp = cmdlookup(command, 0); 8196 find_command(command, &entry, DO_ABS, path);
8198 if (cmdp != NULL) {
8199 entry.cmdtype = cmdp->cmdtype;
8200 entry.u = cmdp->param;
8201 } else {
8202 /* Finally use brute force */
8203 find_command(command, &entry, DO_ABS, path);
8204 }
8205 8197
8206 switch (entry.cmdtype) { 8198 switch (entry.cmdtype) {
8207 case CMDNORMAL: { 8199 case CMDNORMAL: {
@@ -8216,9 +8208,7 @@ describe_command(char *command, const char *path, int describe_command_verbose)
8216 } while (--j >= 0); 8208 } while (--j >= 0);
8217 } 8209 }
8218 if (describe_command_verbose) { 8210 if (describe_command_verbose) {
8219 out1fmt(" is%s %s", 8211 out1fmt(" is %s", p);
8220 (cmdp ? " a tracked alias for" : nullstr), p
8221 );
8222 } else { 8212 } else {
8223 out1str(p); 8213 out1str(p);
8224 } 8214 }