From 41ef232fc522d91f29931ea4ee547432ca8899ee Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 13 Aug 2020 14:27:56 +0100 Subject: win32: use built-in applets for non-existent binaries with Unix-style paths Shell scripts moved from Unix may contain hard-coded paths to binaries such as /bin/sh. A recent commit made it possible to execute such binaries reliably, but that does require them to be installed. As an alternative solution: if a binary with a standard Unix path prefix can't be found but is available as a built-in applet, run the applet. Add the function unix_path() to detect paths starting with /bin, /usr/bin, /sbin or /usr/sbin. Use this function in: - the 'which' applet - shellexec(), describe_command() and find_command() in ash - mingw_spawn_1() See GitHub issue #195. --- debianutils/which.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'debianutils') diff --git a/debianutils/which.c b/debianutils/which.c index c8e99acda..384e2cfec 100644 --- a/debianutils/which.c +++ b/debianutils/which.c @@ -71,6 +71,10 @@ int which_main(int argc UNUSED_PARAM, char **argv) if (strchr(*argv, '/')) { #else if (has_path(*argv)) { +# if ENABLE_FEATURE_SH_STANDALONE + const char *name = bb_basename(*argv); + int is_unix_path = unix_path(*argv); +# endif *argv = auto_add_system_drive(*argv); if ((p=auto_win32_extension(*argv)) != NULL) { missing = 0; @@ -86,6 +90,12 @@ int which_main(int argc UNUSED_PARAM, char **argv) puts(*argv); #endif } +#if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_SH_STANDALONE + else if (is_unix_path && find_applet_by_name(name) >= 0) { + missing = 0; + puts(name); + } +#endif } else { char *path; #if !ENABLE_PLATFORM_MINGW32 -- cgit v1.2.3-55-g6feb