Skip to content

Commit 74b5cfd

Browse files
committed
Refine fix for multibyte char hanling inside command names and args
1 parent b23442f commit 74b5cfd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ext/standard/exec.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,13 @@ PHPAPI char *php_escape_shell_cmd(char *str)
274274
cmd = safe_emalloc(2, l, 1);
275275

276276
for (x = 0, y = 0; x < l; x++) {
277+
int mb_len = php_mblen(str + x, (l - x));
278+
277279
/* skip non-valid multibyte characters */
278-
if (php_mblen(str + x, (l - x)) < 0) {
280+
if (mb_len < 0) {
281+
continue;
282+
} else if (mb_len > 1) {
283+
x += mb_len - 1;
279284
continue;
280285
}
281286

@@ -356,6 +361,16 @@ PHPAPI char *php_escape_shell_arg(char *str)
356361
#endif
357362

358363
for (x = 0; x < l; x++) {
364+
int mb_len = php_mblen(str + x, (l - x));
365+
366+
/* skip non-valid multibyte characters */
367+
if (mb_len < 0) {
368+
continue;
369+
} else if (mb_len > 1) {
370+
x += mb_len - 1;
371+
continue;
372+
}
373+
359374
switch (str[x]) {
360375
#ifdef PHP_WIN32
361376
case '"':

0 commit comments

Comments
 (0)