aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-16 10:03:09 +0100
committerRon Yorston <rmy@pobox.com>2023-04-16 10:03:09 +0100
commit86ff1772f25dff819c1983418ac36822745a6d19 (patch)
treec6be5c1c2e8e734f0921c8346b02c0ed0a5c032d
parente3e510b52695bbf5c55d83c971dc23813325cfc9 (diff)
downloadbusybox-w32-86ff1772f25dff819c1983418ac36822745a6d19.tar.gz
busybox-w32-86ff1772f25dff819c1983418ac36822745a6d19.tar.bz2
busybox-w32-86ff1772f25dff819c1983418ac36822745a6d19.zip
ash: more Unix-style path fixes
Commit 950b318a2 (ash: Unix-style paths, shell builtins and applets) broke running of Unix-style absolute paths from the shell by PATH search. The copy of the program name on the stack should only be used in the first call to tryexec() otherwise it interferes with the use of the stack by padvance(). Also, bring the code to handle Unix-style paths in find_command() into line with the revised code in shellexec().
-rw-r--r--shell/ash.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 0443f1a02..3eb9d5852 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9081,9 +9081,11 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9081#endif 9081#endif
9082 ) { 9082 ) {
9083#if ENABLE_PLATFORM_MINGW32 9083#if ENABLE_PLATFORM_MINGW32
9084 prog = stack_add_ext_space(prog); 9084 char *progext = stack_add_ext_space(prog);
9085#endif 9085 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) progext, argv, envp);
9086#else
9086 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp); 9087 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp);
9088#endif
9087 if (applet_no >= 0) { 9089 if (applet_no >= 0) {
9088 /* We tried execing ourself, but it didn't work. 9090 /* We tried execing ourself, but it didn't work.
9089 * Maybe /proc/self/exe doesn't exist? 9091 * Maybe /proc/self/exe doesn't exist?
@@ -9094,15 +9096,15 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9094 e = errno; 9096 e = errno;
9095#if ENABLE_PLATFORM_MINGW32 9097#if ENABLE_PLATFORM_MINGW32
9096 if (unix_path(prog)) { 9098 if (unix_path(prog)) {
9097# if ENABLE_FEATURE_SH_STANDALONE
9098 const char *name = bb_basename(prog); 9099 const char *name = bb_basename(prog);
9100# if ENABLE_FEATURE_SH_STANDALONE
9099 if ((applet_no = find_applet_by_name(name)) >= 0) { 9101 if ((applet_no = find_applet_by_name(name)) >= 0) {
9100 tryexec(applet_no, name, argv, envp); 9102 tryexec(applet_no, name, argv, envp);
9101 e = errno; 9103 e = errno;
9102 } 9104 }
9103# endif 9105# endif
9104 if (!find_builtin(bb_basename(prog))) { 9106 if (!find_builtin(name)) {
9105 argv[0] = (char *)bb_basename(prog); 9107 argv[0] = (char *)name;
9106 goto try_PATH; 9108 goto try_PATH;
9107 } 9109 }
9108 } 9110 }
@@ -14860,9 +14862,19 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
14860 fullname = stack_add_ext_space(name); 14862 fullname = stack_add_ext_space(name);
14861 if (add_win32_extension(fullname) || file_is_executable(fullname)) { 14863 if (add_win32_extension(fullname) || file_is_executable(fullname)) {
14862 return; 14864 return;
14863 } else if (unix_path(name) && !find_builtin(bb_basename(name))) { 14865 } else if (unix_path(name)) {
14864 name = (char *)bb_basename(name); 14866 name = (char *)bb_basename(name);
14865 act |= DO_NOFUNC; 14867 if (
14868# if ENABLE_FEATURE_SH_STANDALONE
14869 find_applet_by_name(name) >= 0 ||
14870# endif
14871 !find_builtin(bb_basename(name))
14872 ) {
14873 act |= DO_NOFUNC;
14874 } else if (act & DO_ABS) {
14875 entry->cmdtype = CMDUNKNOWN;
14876 return;
14877 }
14866 } else if (act & DO_ABS) { 14878 } else if (act & DO_ABS) {
14867 entry->cmdtype = CMDUNKNOWN; 14879 entry->cmdtype = CMDUNKNOWN;
14868 return; 14880 return;