Skip to content

Commit 92589ad

Browse files
committed
Convert E_ERROR to ValueError in php_escape_shell_arg()
1 parent 85cc2b3 commit 92589ad

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
@@ -402,7 +402,7 @@ PHPAPI zend_string *php_escape_shell_arg(const zend_string *unescaped_arg)
402402

403403
/* max command line length - two single quotes - \0 byte length */
404404
if (l > cmd_max_len - 2 - 1) {
405-
php_error_docref(NULL, E_ERROR, "Argument exceeds the allowed length of %zu bytes", cmd_max_len);
405+
zend_value_error("Argument exceeds the allowed length of %zu bytes", cmd_max_len);
406406
return ZSTR_EMPTY_ALLOC();
407407
}
408408

@@ -461,7 +461,7 @@ PHPAPI zend_string *php_escape_shell_arg(const zend_string *unescaped_arg)
461461
ZSTR_VAL(cmd)[y] = '\0';
462462

463463
if (y > cmd_max_len + 1) {
464-
php_error_docref(NULL, E_ERROR, "Escaped argument exceeds the allowed length of %zu bytes", cmd_max_len);
464+
zend_value_error("Escaped argument exceeds the allowed length of %zu bytes", cmd_max_len);
465465
zend_string_release_ex(cmd, 0);
466466
return ZSTR_EMPTY_ALLOC();
467467
}

ext/standard/tests/general_functions/escapeshellarg_bug71270.phpt

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

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

0 commit comments

Comments
 (0)