aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-06-29 11:46:43 +0100
committerRon Yorston <rmy@pobox.com>2020-06-29 11:46:43 +0100
commit9114e110a59a77909132af6d97bccdf5056adfa4 (patch)
treedc731daf69d0d92d4c08231f97bc0a7b433097ea
parent4f4e9e0d3366ec607d8765278b9753e41bdd544f (diff)
downloadbusybox-w32-9114e110a59a77909132af6d97bccdf5056adfa4.tar.gz
busybox-w32-9114e110a59a77909132af6d97bccdf5056adfa4.tar.bz2
busybox-w32-9114e110a59a77909132af6d97bccdf5056adfa4.zip
ash: avoid duplicated slashes in output of type/command builtins
Microsoft developers have a penchant for adding trailing slashes to entries in PATH: C:/Windows/System32/WindowsPowerShell/v1.0/ C:/Windows/System32/OpenSSH/ The 'type' and 'command -v' shell builtins return paths with duplicated slashes for executables in those directories. See GitHub issue #191. Bonus fixes: - handle backslashes as well as slashes in concat_path_file() - convert backslashes to slashes in the output of 'type', 'command -v'
-rw-r--r--libbb/concat_path_file.c6
-rw-r--r--shell/ash.c4
2 files changed, 10 insertions, 0 deletions
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
index 5b4b7f113..81c7481ca 100644
--- a/libbb/concat_path_file.c
+++ b/libbb/concat_path_file.c
@@ -21,8 +21,14 @@ char* FAST_FUNC concat_path_file(const char *path, const char *filename)
21 21
22 if (!path) 22 if (!path)
23 path = ""; 23 path = "";
24#if ENABLE_PLATFORM_MINGW32
25 lc = last_char_is(path, '/') ?: last_char_is(path, '\\');
26 while (*filename == '/' || *filename == '\\')
27 filename++;
28#else
24 lc = last_char_is(path, '/'); 29 lc = last_char_is(path, '/');
25 while (*filename == '/') 30 while (*filename == '/')
26 filename++; 31 filename++;
32#endif
27 return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename); 33 return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
28} 34}
diff --git a/shell/ash.c b/shell/ash.c
index b51a3fb82..3c53b25ff 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2860,6 +2860,9 @@ padvance_magic(const char **path, const char *name, int magic)
2860 2860
2861 if (len) { 2861 if (len) {
2862 q = mempcpy(q, start, len); 2862 q = mempcpy(q, start, len);
2863#if ENABLE_PLATFORM_MINGW32
2864 if (q[-1] != '/' && q[-1] != '\\')
2865#endif
2863 *q++ = '/'; 2866 *q++ = '/';
2864 } 2867 }
2865 strcpy(q, name); 2868 strcpy(q, name);
@@ -9160,6 +9163,7 @@ describe_command(char *command, const char *path, int describe_command_verbose)
9160 } 9163 }
9161#if ENABLE_PLATFORM_MINGW32 9164#if ENABLE_PLATFORM_MINGW32
9162 add_win32_extension(p); 9165 add_win32_extension(p);
9166 bs_to_slash(p);
9163#endif 9167#endif
9164 if (describe_command_verbose) { 9168 if (describe_command_verbose) {
9165 out1fmt(" is %s", p); 9169 out1fmt(" is %s", p);