aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-03-31 13:04:23 +0100
committerRon Yorston <rmy@pobox.com>2023-03-31 13:04:23 +0100
commit950b318a2a11264dd608c6ab9ee3ed3d06db4ef9 (patch)
tree2bec0d0cf4b8e29049d0ed3f09f152bce76f0821 /shell
parent5ead1485640c81d0b020768d59a32d9029a164ee (diff)
downloadbusybox-w32-950b318a2a11264dd608c6ab9ee3ed3d06db4ef9.tar.gz
busybox-w32-950b318a2a11264dd608c6ab9ee3ed3d06db4ef9.tar.bz2
busybox-w32-950b318a2a11264dd608c6ab9ee3ed3d06db4ef9.zip
ash: Unix-style paths, shell builtins and applets
Some shell builtins also exist as applets: echo, printf, pwd and test, for example. If such an applet is referenced using a Unix- style path, e.g. /usr/bin/echo, the applet should be run rather than the builtin. Instead the current code says: sh: /usr/bin/echo: file not found Rearrange the tests in shellexec() so the correct behaviour occurs. Actually, the error message was also incorrect due to a separate bug. Commit d71cb67ff (win32: revert special treatment of Unix-style absolute paths) failed to allocate space on the stack so that the command passed to tryexec() could have an extension added if required.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 913f0ce22..521ab22af 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9088,6 +9088,7 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9088 || (applet_no = find_applet_by_name(prog)) >= 0 9088 || (applet_no = find_applet_by_name(prog)) >= 0
9089#endif 9089#endif
9090 ) { 9090 ) {
9091 prog = stack_add_ext_space(prog);
9091 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp); 9092 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp);
9092 if (applet_no >= 0) { 9093 if (applet_no >= 0) {
9093 /* We tried execing ourself, but it didn't work. 9094 /* We tried execing ourself, but it didn't work.
@@ -9098,7 +9099,7 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9098 } 9099 }
9099 e = errno; 9100 e = errno;
9100#if ENABLE_PLATFORM_MINGW32 9101#if ENABLE_PLATFORM_MINGW32
9101 if (unix_path(prog) && !find_builtin(bb_basename(prog))) { 9102 if (unix_path(prog)) {
9102# if ENABLE_FEATURE_SH_STANDALONE 9103# if ENABLE_FEATURE_SH_STANDALONE
9103 const char *name = bb_basename(prog); 9104 const char *name = bb_basename(prog);
9104 if ((applet_no = find_applet_by_name(name)) >= 0) { 9105 if ((applet_no = find_applet_by_name(name)) >= 0) {
@@ -9106,8 +9107,10 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9106 e = errno; 9107 e = errno;
9107 } 9108 }
9108# endif 9109# endif
9109 argv[0] = (char *)bb_basename(prog); 9110 if (!find_builtin(bb_basename(prog))) {
9110 goto try_PATH; 9111 argv[0] = (char *)bb_basename(prog);
9112 goto try_PATH;
9113 }
9111 } 9114 }
9112#endif 9115#endif
9113 } else { 9116 } else {