projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
be9de11
)
Escape arguments for Windows in shell-tools.c
author
Ian Lynagh
<igloo@earth.li>
Wed, 23 Jan 2008 15:17:24 +0000
(15:17 +0000)
committer
Ian Lynagh
<igloo@earth.li>
Wed, 23 Jan 2008 15:17:24 +0000
(15:17 +0000)
includes/shell-tools.c
patch
|
blob
|
history
diff --git
a/includes/shell-tools.c
b/includes/shell-tools.c
index
29b2e2d
..
4aebaf9
100644
(file)
--- a/
includes/shell-tools.c
+++ b/
includes/shell-tools.c
@@
-59,7
+59,8
@@
int run(char *this, char *program, int argc, char** argv) {
cmdline_len = 0;
for(i = 1; i < argc; i++) {
/* Note: play it safe and quote all argv strings */
cmdline_len = 0;
for(i = 1; i < argc; i++) {
/* Note: play it safe and quote all argv strings */
- cmdline_len += 1 + strlen(argv[i]) + 2;
+ /* In the worst case we have to escape every character with a \ */
+ cmdline_len += 1 + 2 * strlen(argv[i]) + 2;
}
new_cmdline = (char*)malloc(sizeof(char) * (cmdline_len + 1));
if (!new_cmdline) {
}
new_cmdline = (char*)malloc(sizeof(char) * (cmdline_len + 1));
if (!new_cmdline) {
@@
-73,6
+74,10
@@
int run(char *this, char *program, int argc, char** argv) {
*ptr++ = '"';
src = argv[i];
while(*src) {
*ptr++ = '"';
src = argv[i];
while(*src) {
+ /* Escape any \ and " characters */
+ if ((*src == '\\') || (*src == '"')) {
+ *ptr++ = '\\';
+ }
*ptr++ = *src++;
}
*ptr++ = '"';
*ptr++ = *src++;
}
*ptr++ = '"';