aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debianutils/which.c6
-rw-r--r--include/mingw.h2
-rw-r--r--libbb/executable.c2
-rw-r--r--libbb/lineedit.c3
-rw-r--r--shell/ash.c45
-rw-r--r--win32/mingw.c11
-rw-r--r--win32/process.c4
7 files changed, 24 insertions, 49 deletions
diff --git a/debianutils/which.c b/debianutils/which.c
index 4590653b3..b2cd4de18 100644
--- a/debianutils/which.c
+++ b/debianutils/which.c
@@ -12,9 +12,9 @@
12//config: which is used to find programs in your PATH and 12//config: which is used to find programs in your PATH and
13//config: print out their pathnames. 13//config: print out their pathnames.
14 14
15// NOTE: For WIN32 this applet is NOEXEC as alloc_system_drive() and 15// NOTE: For WIN32 this applet is NOEXEC as alloc_ext_space() and
16// find_executable() both allocate memory. And find_executable() 16// find_executable() both allocate memory. And find_executable()
17// calls alloc_system_drive(). 17// calls alloc_ext_space().
18 18
19//applet:IF_PLATFORM_MINGW32(IF_WHICH(APPLET_NOEXEC(which, which, BB_DIR_USR_BIN, BB_SUID_DROP, which))) 19//applet:IF_PLATFORM_MINGW32(IF_WHICH(APPLET_NOEXEC(which, which, BB_DIR_USR_BIN, BB_SUID_DROP, which)))
20//applet:IF_PLATFORM_POSIX(IF_WHICH(APPLET_NOFORK(which, which, BB_DIR_USR_BIN, BB_SUID_DROP, which))) 20//applet:IF_PLATFORM_POSIX(IF_WHICH(APPLET_NOFORK(which, which, BB_DIR_USR_BIN, BB_SUID_DROP, which)))
@@ -87,7 +87,7 @@ int which_main(int argc UNUSED_PARAM, char **argv)
87 } 87 }
88#else 88#else
89 if (has_path(*argv)) { 89 if (has_path(*argv)) {
90 char *path = alloc_system_drive(*argv); 90 char *path = alloc_ext_space(*argv);
91 91
92 if (add_win32_extension(path) || file_is_executable(path)) { 92 if (add_win32_extension(path) || file_is_executable(path)) {
93 missing = 0; 93 missing = 0;
diff --git a/include/mingw.h b/include/mingw.h
index bfd6128e1..0357e4521 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -575,7 +575,7 @@ int unc_root_len(const char *dir);
575int root_len(const char *path); 575int root_len(const char *path);
576const char *get_system_drive(void); 576const char *get_system_drive(void);
577const char *need_system_drive(const char *path); 577const char *need_system_drive(const char *path);
578char *alloc_system_drive(const char *path); 578char *alloc_ext_space(const char *path);
579int chdir_system_drive(void); 579int chdir_system_drive(void);
580char *xabsolute_path(char *path); 580char *xabsolute_path(char *path);
581char *get_drive_cwd(const char *path, char *buffer, int size); 581char *get_drive_cwd(const char *path, char *buffer, int size);
diff --git a/libbb/executable.c b/libbb/executable.c
index 32b37f29d..770aedc0c 100644
--- a/libbb/executable.c
+++ b/libbb/executable.c
@@ -57,7 +57,7 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
57 ); 57 );
58#if ENABLE_PLATFORM_MINGW32 58#if ENABLE_PLATFORM_MINGW32
59 { 59 {
60 char *w = alloc_system_drive(p); 60 char *w = alloc_ext_space(p);
61 ex = add_win32_extension(w) || file_is_executable(w); 61 ex = add_win32_extension(w) || file_is_executable(w);
62 free(p); 62 free(p);
63 p = w; 63 p = w;
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index c5d5808f5..b4950688e 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -972,9 +972,6 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
972 } 972 }
973 973
974 lpath = *paths[i] ? paths[i] : "."; 974 lpath = *paths[i] ? paths[i] : ".";
975#if ENABLE_PLATFORM_MINGW32
976 lpath = auto_string(alloc_system_drive(lpath));
977#endif
978 dir = opendir(lpath); 975 dir = opendir(lpath);
979 if (!dir) 976 if (!dir)
980 continue; /* don't print an error */ 977 continue; /* don't print an error */
diff --git a/shell/ash.c b/shell/ash.c
index 8497538b1..13200da0c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2158,17 +2158,13 @@ maybe_single_quote(const char *s)
2158} 2158}
2159 2159
2160#if ENABLE_PLATFORM_MINGW32 2160#if ENABLE_PLATFORM_MINGW32
2161/* 2161/* Copy path to a string on the stack long enough to allow a file extension
2162 * Place 'path' in a string on the stack, adding the system drive prefix 2162 * to be added. */
2163 * if necessary and leaving room for an optional extension.
2164 */
2165static char * 2163static char *
2166stack_add_system_drive(const char *path) 2164stack_add_ext_space(const char *path)
2167{ 2165{
2168 const char *sd = need_system_drive(path); 2166 char *p = growstackto(strlen(path) + 5);
2169 char *p = growstackto(strlen(path) + 5 + (sd ? strlen(sd) : 0)); 2167 strcpy(p, path);
2170
2171 strcpy(stpcpy(p, sd ?: ""), path);
2172 return p; 2168 return p;
2173} 2169}
2174#endif 2170#endif
@@ -2947,10 +2943,6 @@ padvance_magic(const char **path, const char *name, int magic)
2947 const char *start; 2943 const char *start;
2948 size_t qlen; 2944 size_t qlen;
2949 size_t len; 2945 size_t len;
2950#if ENABLE_PLATFORM_MINGW32
2951 size_t sdlen = 0;
2952 const char *sd;
2953#endif
2954 2946
2955 if (*path == NULL) 2947 if (*path == NULL)
2956 return -1; 2948 return -1;
@@ -2982,20 +2974,11 @@ padvance_magic(const char **path, const char *name, int magic)
2982 *path = *p == PATH_SEP ? p + 1 : NULL; 2974 *path = *p == PATH_SEP ? p + 1 : NULL;
2983 2975
2984 /* "2" is for '/' and '\0' */ 2976 /* "2" is for '/' and '\0' */
2985 qlen = len + strlen(name) + 2; 2977 /* reserve space for suffix on WIN32 */
2986#if ENABLE_PLATFORM_MINGW32 2978 qlen = len + strlen(name) + 2 IF_PLATFORM_MINGW32(+ 4);
2987 /* reserve space for system drive prefix and extension */
2988 sd = need_system_drive(start);
2989 if (sd != NULL)
2990 sdlen = strlen(sd);
2991 qlen += 4 + sdlen;
2992#endif
2993 q = growstackto(qlen); 2979 q = growstackto(qlen);
2994 2980
2995 if (len) { 2981 if (len) {
2996#if ENABLE_PLATFORM_MINGW32
2997 q = mempcpy(q, sd, sdlen);
2998#endif
2999 q = mempcpy(q, start, len); 2982 q = mempcpy(q, start, len);
3000#if ENABLE_PLATFORM_MINGW32 2983#if ENABLE_PLATFORM_MINGW32
3001 if (q[-1] != '/' && q[-1] != '\\') 2984 if (q[-1] != '/' && q[-1] != '\\')
@@ -9058,10 +9041,6 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9058 || (applet_no = find_applet_by_name(prog)) >= 0 9041 || (applet_no = find_applet_by_name(prog)) >= 0
9059#endif 9042#endif
9060 ) { 9043 ) {
9061#if ENABLE_PLATFORM_MINGW32
9062 char *oldprog = prog;
9063 prog = stack_add_system_drive(prog);
9064#endif
9065 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp); 9044 tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp);
9066 if (applet_no >= 0) { 9045 if (applet_no >= 0) {
9067 /* We tried execing ourself, but it didn't work. 9046 /* We tried execing ourself, but it didn't work.
@@ -9072,15 +9051,15 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
9072 } 9051 }
9073 e = errno; 9052 e = errno;
9074#if ENABLE_PLATFORM_MINGW32 9053#if ENABLE_PLATFORM_MINGW32
9075 if (unix_path(oldprog) && !find_builtin(bb_basename(oldprog))) { 9054 if (unix_path(prog) && !find_builtin(bb_basename(prog))) {
9076# if ENABLE_FEATURE_SH_STANDALONE 9055# if ENABLE_FEATURE_SH_STANDALONE
9077 const char *name = bb_basename(oldprog); 9056 const char *name = bb_basename(prog);
9078 if ((applet_no = find_applet_by_name(name)) >= 0) { 9057 if ((applet_no = find_applet_by_name(name)) >= 0) {
9079 tryexec(applet_no, name, argv, envp); 9058 tryexec(applet_no, name, argv, envp);
9080 e = errno; 9059 e = errno;
9081 } 9060 }
9082# endif 9061# endif
9083 argv[0] = (char *)bb_basename(oldprog); 9062 argv[0] = (char *)bb_basename(prog);
9084 goto try_PATH; 9063 goto try_PATH;
9085 } 9064 }
9086#endif 9065#endif
@@ -9523,7 +9502,7 @@ describe_command(char *command, const char *path, int describe_command_verbose)
9523#endif 9502#endif
9524 if (j < 0) { 9503 if (j < 0) {
9525#if ENABLE_PLATFORM_MINGW32 9504#if ENABLE_PLATFORM_MINGW32
9526 p = stack_add_system_drive(command); 9505 p = stack_add_ext_space(command);
9527#else 9506#else
9528 p = command; 9507 p = command;
9529#endif 9508#endif
@@ -14720,7 +14699,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
14720 if (has_path(name)) { 14699 if (has_path(name)) {
14721 entry->u.index = -1; 14700 entry->u.index = -1;
14722 entry->cmdtype = CMDNORMAL; 14701 entry->cmdtype = CMDNORMAL;
14723 fullname = stack_add_system_drive(name); 14702 fullname = stack_add_ext_space(name);
14724 if (add_win32_extension(fullname) || file_is_executable(fullname)) { 14703 if (add_win32_extension(fullname) || file_is_executable(fullname)) {
14725 return; 14704 return;
14726 } else if (unix_path(name) && !find_builtin(bb_basename(name))) { 14705 } else if (unix_path(name) && !find_builtin(bb_basename(name))) {
diff --git a/win32/mingw.c b/win32/mingw.c
index d5d944a9d..606a48319 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2142,13 +2142,12 @@ const char *need_system_drive(const char *path)
2142 return NULL; 2142 return NULL;
2143} 2143}
2144 2144
2145/* Allocate a string long enough to allow a system drive prefix and 2145/* Copy path to an allocated string long enough to allow a file extension
2146 * file extension to be added to path. Add the prefix if necessary. */ 2146 * to be added. */
2147char *alloc_system_drive(const char *path) 2147char *alloc_ext_space(const char *path)
2148{ 2148{
2149 const char *sd = need_system_drive(path); 2149 char *s = xmalloc(strlen(path) + 5);
2150 char *s = xmalloc(strlen(path) + 5 + (sd ? strlen(sd) : 0)); 2150 strcpy(s, path);
2151 strcpy(stpcpy(s, sd ?: ""), path);
2152 return s; 2151 return s;
2153} 2152}
2154 2153
diff --git a/win32/process.c b/win32/process.c
index 6ab0d8735..d78041251 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -328,7 +328,7 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv,
328 } 328 }
329#endif 329#endif
330 330
331 path = alloc_system_drive(interp.path); 331 path = alloc_ext_space(interp.path);
332 if ((add_win32_extension(path) || file_is_executable(path))) { 332 if ((add_win32_extension(path) || file_is_executable(path))) {
333 new_argv[0] = path; 333 new_argv[0] = path;
334 ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); 334 ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level);
@@ -363,7 +363,7 @@ mingw_spawnvp(int mode, const char *cmd, char *const *argv)
363 return mingw_spawn_applet(mode, argv, NULL); 363 return mingw_spawn_applet(mode, argv, NULL);
364#endif 364#endif
365 if (has_path(cmd)) { 365 if (has_path(cmd)) {
366 path = alloc_system_drive(cmd); 366 path = alloc_ext_space(cmd);
367 if (add_win32_extension(path) || file_is_executable(path)) { 367 if (add_win32_extension(path) || file_is_executable(path)) {
368 ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0); 368 ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0);
369 free(path); 369 free(path);