summaryrefslogtreecommitdiff
path: root/includes/shell-tools.c
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2008-01-23 15:17:24 +0000
committerIan Lynagh <igloo@earth.li>2008-01-23 15:17:24 +0000
commit867d76ddb9b4231f36e85abd68c1ed26d834d039 (patch)
tree16b9bb09d8f3657fde765a0bc548a1bc8a498bfd /includes/shell-tools.c
parentbe9de111a5f9ba0e9716851b30f3b79be370a102 (diff)
downloadhaskell-867d76ddb9b4231f36e85abd68c1ed26d834d039.tar.gz
Escape arguments for Windows in shell-tools.c
Diffstat (limited to 'includes/shell-tools.c')
-rw-r--r--includes/shell-tools.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/includes/shell-tools.c b/includes/shell-tools.c
index 29b2e2d45b..4aebaf94f3 100644
--- 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 += 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) {
@@ -73,6 +74,10 @@ int run(char *this, char *program, int argc, char** argv) {
*ptr++ = '"';
src = argv[i];
while(*src) {
+ /* Escape any \ and " characters */
+ if ((*src == '\\') || (*src == '"')) {
+ *ptr++ = '\\';
+ }
*ptr++ = *src++;
}
*ptr++ = '"';