]> granicus.if.org Git - php/commitdiff
Refine fix for multibyte char hanling inside command names and args
authorIlia Alshanetsky <iliaa@php.net>
Thu, 20 Mar 2008 23:25:31 +0000 (23:25 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 20 Mar 2008 23:25:31 +0000 (23:25 +0000)
ext/standard/exec.c

index f1b9906409166fb03b13af22b51231be88208925..cb7e92cc06f50a83198e45e032fb3604f257f096 100644 (file)
@@ -274,8 +274,13 @@ PHPAPI char *php_escape_shell_cmd(char *str)
        cmd = safe_emalloc(2, l, 1);
 
        for (x = 0, y = 0; x < l; x++) {
+               int mb_len = php_mblen(str + x, (l - x));
+
                /* skip non-valid multibyte characters */
-               if (php_mblen(str + x, (l - x)) < 0) {
+               if (mb_len < 0) {
+                       continue;
+               } else if (mb_len > 1) {
+                       x += mb_len - 1;
                        continue;
                }
 
@@ -356,6 +361,16 @@ PHPAPI char *php_escape_shell_arg(char *str)
 #endif
 
        for (x = 0; x < l; x++) {
+               int mb_len = php_mblen(str + x, (l - x));
+
+               /* skip non-valid multibyte characters */
+               if (mb_len < 0) {
+                       continue;
+               } else if (mb_len > 1) {
+                       x += mb_len - 1;
+                       continue;
+               }
+
                switch (str[x]) {
 #ifdef PHP_WIN32
                case '"':