From: Ilia Alshanetsky Date: Thu, 20 Mar 2008 23:26:01 +0000 (+0000) Subject: MFB: Refine fix for multibyte char hanling inside command names and args X-Git-Tag: RELEASE_2_0_0a1~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b986dfaaaea377d607c9f33326da917c9c5984d7;p=php MFB: Refine fix for multibyte char hanling inside command names and args --- diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 95116ff320..c545cfc3c1 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -259,8 +259,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; } @@ -341,6 +346,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 '"':