aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2026-02-14 21:09:47 +0000
committerRon Yorston <rmy@pobox.com>2026-02-14 21:09:47 +0000
commit686a0803f9747206eef5337100c5338431891e45 (patch)
tree19c1609ec6227701bddb11fde4af346287aea091
parentde7b34e8c779d8baca5abba1394284e0b6e87dc6 (diff)
downloadbusybox-w32-686a0803f9747206eef5337100c5338431891e45.tar.gz
busybox-w32-686a0803f9747206eef5337100c5338431891e45.tar.bz2
busybox-w32-686a0803f9747206eef5337100c5338431891e45.zip
ash: fix execution of applets via Unix-style pathHEADmaster
Merging of upstream changes to ash failed to ensure that applets could be executed using a Unix-style path. Move the necessary code from shellexec() to tryexec(). (GitHub issue #565)
-rw-r--r--shell/ash.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/shell/ash.c b/shell/ash.c
index bb8ac53d6..f439d5d79 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6939,13 +6939,27 @@ tryexec_applet(int applet_no, int noexec, const char *cmd, char **argv, char **e
6939#endif 6939#endif
6940 6940
6941#if ENABLE_PLATFORM_MINGW32 6941#if ENABLE_PLATFORM_MINGW32
6942static struct builtincmd *find_builtin(const char *name);
6942static void 6943static void
6943tryexec(const char *cmd, const char *path, int noexec, char **argv, char **envp) 6944tryexec(const char *cmd, const char *path, int noexec, char **argv, char **envp)
6944{ 6945{
6945#if ENABLE_FEATURE_SH_STANDALONE 6946#if ENABLE_FEATURE_SH_STANDALONE
6946 interp_t interp; 6947 interp_t interp;
6948 int applet_no;
6947#endif 6949#endif
6948 6950
6951 if (unix_path(cmd)) {
6952 const char *name = bb_basename(cmd);
6953# if ENABLE_FEATURE_SH_STANDALONE
6954 if ((applet_no = find_applet_by_name_for_sh(name, path)) >= 0) {
6955 tryexec_applet(applet_no, noexec, name, argv, envp);
6956 }
6957# endif
6958 if (!find_builtin(name)) {
6959 argv[0] = (char *)name;
6960 }
6961 }
6962
6949 /* Workaround for libtool, which assumes the host is an MSYS2 6963 /* Workaround for libtool, which assumes the host is an MSYS2
6950 * environment and requires special-case escaping for cmd.exe. 6964 * environment and requires special-case escaping for cmd.exe.
6951 * https://github.com/skeeto/w64devkit/issues/50 */ 6965 * https://github.com/skeeto/w64devkit/issues/50 */
@@ -6963,7 +6977,7 @@ tryexec(const char *cmd, const char *path, int noexec, char **argv, char **envp)
6963 /* If the command is a script with an interpreter which is an 6977 /* If the command is a script with an interpreter which is an
6964 * applet, we can run it as if it were a noexec applet. */ 6978 * applet, we can run it as if it were a noexec applet. */
6965 if (parse_interpreter(cmd, &interp)) { 6979 if (parse_interpreter(cmd, &interp)) {
6966 int applet_no = find_applet_by_name_for_sh(interp.name, path); 6980 applet_no = find_applet_by_name_for_sh(interp.name, path);
6967 6981
6968 if (applet_no >= 0) { 6982 if (applet_no >= 0) {
6969 argv[0] = (char *)cmd; 6983 argv[0] = (char *)cmd;
@@ -7034,9 +7048,6 @@ tryexec(const char *cmd, char **argv, char **envp)
7034 * have to change the find_command routine as well. 7048 * have to change the find_command routine as well.
7035 * argv[-1] must exist and be writable! See tryexec() for why. 7049 * argv[-1] must exist and be writable! See tryexec() for why.
7036 */ 7050 */
7037#if ENABLE_PLATFORM_MINGW32
7038static struct builtincmd *find_builtin(const char *name);
7039#endif
7040static void shellexec(char *prog, char **argv, const char *path, int idx, int noexec) 7051static void shellexec(char *prog, char **argv, const char *path, int idx, int noexec)
7041{ 7052{
7042 char *cmdname; 7053 char *cmdname;
@@ -7070,20 +7081,6 @@ static void shellexec(char *prog, char **argv, const char *path, int idx, int no
7070 * Maybe /proc/self/exe doesn't exist? 7081 * Maybe /proc/self/exe doesn't exist?
7071 */ 7082 */
7072#endif 7083#endif
7073#if ENABLE_PLATFORM_MINGW32
7074 if (unix_path(prog)) {
7075 const char *name = bb_basename(prog);
7076# if ENABLE_FEATURE_SH_STANDALONE
7077 if ((applet_no = find_applet_by_name_for_sh(name, path)) >= 0) {
7078 tryexec_applet(applet_no, noexec, name, argv, envp);
7079 e = errno;
7080 }
7081# endif
7082 if (!find_builtin(name)) {
7083 argv[0] = (char *)name;
7084 }
7085 }
7086#endif
7087 e = ENOENT; 7084 e = ENOENT;
7088 while (padvance(&path, argv[0]) >= 0) { 7085 while (padvance(&path, argv[0]) >= 0) {
7089 cmdname = stackblock(); 7086 cmdname = stackblock();