From 950b318a2a11264dd608c6ab9ee3ed3d06db4ef9 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 31 Mar 2023 13:04:23 +0100 Subject: 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. --- shell/ash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'shell') 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) || (applet_no = find_applet_by_name(prog)) >= 0 #endif ) { + prog = stack_add_ext_space(prog); tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp); if (applet_no >= 0) { /* 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) } e = errno; #if ENABLE_PLATFORM_MINGW32 - if (unix_path(prog) && !find_builtin(bb_basename(prog))) { + if (unix_path(prog)) { # if ENABLE_FEATURE_SH_STANDALONE const char *name = bb_basename(prog); 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) e = errno; } # endif - argv[0] = (char *)bb_basename(prog); - goto try_PATH; + if (!find_builtin(bb_basename(prog))) { + argv[0] = (char *)bb_basename(prog); + goto try_PATH; + } } #endif } else { -- cgit v1.2.3-55-g6feb