From 74b5cfdea54ccddf2db7daa2e6c83a26f06e1950 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 20 Mar 2008 23:25:31 +0000 Subject: [PATCH] Refine fix for multibyte char hanling inside command names and args --- ext/standard/exec.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/standard/exec.c b/ext/standard/exec.c index f1b9906409..cb7e92cc06 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -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 '"': -- 2.40.0