Skip to content

Commit db6ba01

Browse files
committed
Convert E_ERROR to ValueError in php_escape_shell_cmd()
1 parent d06081b commit db6ba01

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ext/standard/exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ PHPAPI zend_string *php_escape_shell_cmd(const zend_string *unescaped_cmd)
295295

296296
/* max command line length - two single quotes - \0 byte length */
297297
if (l > cmd_max_len - 2 - 1) {
298-
php_error_docref(NULL, E_ERROR, "Command exceeds the allowed length of %zu bytes", cmd_max_len);
298+
zend_value_error("Command exceeds the allowed length of %zu bytes", cmd_max_len);
299299
return ZSTR_EMPTY_ALLOC();
300300
}
301301

@@ -371,7 +371,7 @@ PHPAPI zend_string *php_escape_shell_cmd(const zend_string *unescaped_cmd)
371371
ZSTR_VAL(cmd)[y] = '\0';
372372

373373
if (y > cmd_max_len + 1) {
374-
php_error_docref(NULL, E_ERROR, "Escaped command exceeds the allowed length of %zu bytes", cmd_max_len);
374+
zend_value_error("Escaped command exceeds the allowed length of %zu bytes", cmd_max_len);
375375
zend_string_release_ex(cmd, 0);
376376
return ZSTR_EMPTY_ALLOC();
377377
}

ext/standard/tests/general_functions/escapeshellcmd_bug71270.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ Test escapeshellcmd() allowed argument length
44
<?php
55
ini_set('memory_limit', -1);
66
$var_2 = str_repeat('A', 1024*1024*64);
7-
escapeshellcmd($var_2);
7+
8+
try {
9+
escapeshellcmd($var_2);
10+
} catch (Throwable $e) {
11+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
12+
}
813

914
?>
1015
===DONE===
1116
--EXPECTF--
12-
Fatal error: escapeshellcmd(): Command exceeds the allowed length of %d bytes in %s on line %d
17+
ValueError: Command exceeds the allowed length of %d bytes
18+
===DONE===

0 commit comments

Comments
 (0)