]> granicus.if.org Git - php/commitdiff
Fixed: virtual_popen in ZTS mode
authorStefan Esser <sesser@php.net>
Thu, 2 Dec 2004 01:04:23 +0000 (01:04 +0000)
committerStefan Esser <sesser@php.net>
Thu, 2 Dec 2004 01:04:23 +0000 (01:04 +0000)
TSRM/tsrm_virtual_cwd.c

index 969628c4b800f8c02e0b110fc885433ccdbe7623..0a351db57fa9cd88ae9671c263a949721503022a 100644 (file)
@@ -969,13 +969,24 @@ CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
 CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
 {
        int command_length;
+       int dir_length, extra = 0;
        char *command_line;
-       char *ptr;
+       char *ptr, *dir;
        FILE *retval;
 
        command_length = strlen(command);
 
-       ptr = command_line = (char *) malloc(command_length + sizeof("cd  ; ") + CWDG(cwd).cwd_length+1);
+       dir_length = CWDG(cwd).cwd_length;
+       dir = CWDG(cwd).cwd;
+       while (dir_length > 0) {
+               if (*dir == '\'') extra+=3;
+               dir++;
+               dir_length--;
+       }
+       dir_length = CWDG(cwd).cwd_length;
+       dir = CWDG(cwd).cwd;
+
+       ptr = command_line = (char *) malloc(command_length + sizeof("cd '' ; ") + dir_length +1+1);
        if (!command_line) {
                return NULL;
        }
@@ -985,8 +996,21 @@ CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
        if (CWDG(cwd).cwd_length == 0) {
                *ptr++ = DEFAULT_SLASH;
        } else {
-               memcpy(ptr, CWDG(cwd).cwd, CWDG(cwd).cwd_length);
-               ptr += CWDG(cwd).cwd_length;
+               *ptr++ = '\'';
+               while (dir_length > 0) {
+                       switch (*dir) {
+                       case '\'':
+                               *ptr++ = '\'';
+                               *ptr++ = '\\';
+                               *ptr++ = '\'';
+                               /* fall-through */
+                       default:
+                               *ptr++ = *dir;
+                       }
+                       dir++;
+                       dir_length--;
+               }
+               *ptr++ = '\'';
        }
        
        *ptr++ = ' ';