]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #18291 (escapeshellcmd() can now handle quoted arguments)
authorIlia Alshanetsky <iliaa@php.net>
Tue, 5 Aug 2003 20:16:47 +0000 (20:16 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 5 Aug 2003 20:16:47 +0000 (20:16 +0000)
NEWS
ext/standard/exec.c

diff --git a/NEWS b/NEWS
index 1aa1de21fa7affc1c8b36b2d8854f2b171c25772..b4ddad708447172ad5262ce4de55b82fdbdf24ba 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ PHP 4                                                                      NEWS
 - Fixed bug #22072 (Apache2 sapis do not detect aborted connections). (Ilia)
 - Fixed bug #21611 (version_compare() does not support "p" as suffix).
   (Stefan Walk)
+- Fixed bug #18291 (escapeshellcmd() can now handle quoted arguments). (Ilia)
 - Fixed bug #17414 (pthreads bug workaround). (timo.teras[at]iki.fi)
 
 30 Jul 2003, Version 4.3.3RC2
index 4c573c6032000331adf76d4c6ce231ba0e3b4c94..80e247e11bbb39bf586099d846cc07357cbdb01b 100644 (file)
@@ -401,18 +401,28 @@ PHP_FUNCTION(passthru)
 char *php_escape_shell_cmd(char *str) {
        register int x, y, l;
        char *cmd;
+       char *p = NULL;
 
        l = strlen(str);
        cmd = emalloc(2 * l + 1);
        
        for (x = 0, y = 0; x < l; x++) {
                switch (str[x]) {
+                       case '"':
+                       case '\'':
+                               if (!p && (p = memchr(str + x + 1, str[x], l - x - 1))) {
+                                       /* noop */
+                               } else if (p && *p == str[x]) {
+                                       p = NULL;
+                               } else {
+                                       cmd[y++] = '\\';
+                               }
+                               cmd[y++] = str[x];
+                               break;
                        case '#': /* This is character-set independent */
                        case '&':
                        case ';':
                        case '`':
-                       case '\'':
-                       case '"':
                        case '|':
                        case '*':
                        case '?':