aboutsummaryrefslogtreecommitdiff
path: root/win32
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 /win32
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.
Diffstat (limited to 'win32')
-rw-r--r--win32/process.c14
1 files changed, 7 insertions, 7 deletions
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}