aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-10-05 11:18:05 +0100
committerRon Yorston <rmy@pobox.com>2012-10-05 11:18:05 +0100
commit239bba0059e5c8284c7f21e2b65b0467b20c6bd7 (patch)
treec19ff4fbe7ccfd2c453bfc291d6d375e54249edf
parent01366408c9df773897bdd669cd4371d099f483bb (diff)
downloadbusybox-w32-239bba0059e5c8284c7f21e2b65b0467b20c6bd7.tar.gz
busybox-w32-239bba0059e5c8284c7f21e2b65b0467b20c6bd7.tar.bz2
busybox-w32-239bba0059e5c8284c7f21e2b65b0467b20c6bd7.zip
Revised quoting of command line arguments for WIN32
* We only need to quote an argument if it contains whitespace. * There's no point in quoting ? or * because Windows still expands them. Anyhow, if the command line comes from a BusyBox shell it will usually have handled the globbing, so we should turn off Windows globbing for any wildcard that has made it through the shell without expansion. This means that BusyBox commands run from cmd.exe won't do wildcard expansion, though. * Backslashes only need to be doubled if they occur immediately before double quotes. * Double quotes need to be escaped with a backslash.
-rw-r--r--applets/applets.c5
-rw-r--r--libbb/appletlib.c5
-rw-r--r--win32/process.c14
3 files changed, 17 insertions, 7 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 98c2b44f5..7ffa7a896 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -9,6 +9,11 @@
9#include "busybox.h" 9#include "busybox.h"
10 10
11#if ENABLE_BUILD_LIBBUSYBOX 11#if ENABLE_BUILD_LIBBUSYBOX
12#if ENABLE_PLATFORM_MINGW32
13/* disable MSVCRT command line globbing */
14int _CRT_glob = 0;
15#endif
16
12int main(int argc UNUSED_PARAM, char **argv) 17int main(int argc UNUSED_PARAM, char **argv)
13{ 18{
14 return lbb_main(argv); 19 return lbb_main(argv);
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 0c0d14499..9f3584755 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -773,6 +773,11 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv)
773#if ENABLE_BUILD_LIBBUSYBOX 773#if ENABLE_BUILD_LIBBUSYBOX
774int lbb_main(char **argv) 774int lbb_main(char **argv)
775#else 775#else
776#if ENABLE_PLATFORM_MINGW32
777/* disable MSVCRT command line globbing */
778int _CRT_glob = 0;
779#endif
780
776int main(int argc UNUSED_PARAM, char **argv) 781int main(int argc UNUSED_PARAM, char **argv)
777#endif 782#endif
778{ 783{
diff --git a/win32/process.c b/win32/process.c
index 53ad44a42..59bc5b4a0 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -117,7 +117,7 @@ quote_arg(const char *arg)
117 const char *p = arg; 117 const char *p = arg;
118 if (!*p) force_quotes = 1; 118 if (!*p) force_quotes = 1;
119 while (*p) { 119 while (*p) {
120 if (isspace(*p) || *p == '*' || *p == '?' || *p == '{' || *p == '\'') 120 if (isspace(*p))
121 force_quotes = 1; 121 force_quotes = 1;
122 else if (*p == '"') 122 else if (*p == '"')
123 n++; 123 n++;
@@ -130,8 +130,6 @@ quote_arg(const char *arg)
130 } 130 }
131 if (*p == '"') 131 if (*p == '"')
132 n += count*2 + 1; 132 n += count*2 + 1;
133 else
134 n += count;
135 continue; 133 continue;
136 } 134 }
137 len++; 135 len++;
@@ -142,7 +140,8 @@ quote_arg(const char *arg)
142 140
143 /* insert \ where necessary */ 141 /* insert \ where necessary */
144 d = q = xmalloc(len+n+3); 142 d = q = xmalloc(len+n+3);
145 *d++ = '"'; 143 if (force_quotes)
144 *d++ = '"';
146 while (*arg) { 145 while (*arg) {
147 if (*arg == '"') 146 if (*arg == '"')
148 *d++ = '\\'; 147 *d++ = '\\';
@@ -152,15 +151,16 @@ quote_arg(const char *arg)
152 count++; 151 count++;
153 *d++ = *arg++; 152 *d++ = *arg++;
154 } 153 }
155 while (count-- > 0)
156 *d++ = '\\';
157 if (*arg == '"') { 154 if (*arg == '"') {
155 while (count-- > 0)
156 *d++ = '\\';
158 *d++ = '\\'; 157 *d++ = '\\';
159 } 158 }
160 } 159 }
161 *d++ = *arg++; 160 *d++ = *arg++;
162 } 161 }
163 *d++ = '"'; 162 if (force_quotes)
163 *d++ = '"';
164 *d++ = 0; 164 *d++ = 0;
165 return q; 165 return q;
166} 166}