Skip to content

Commit 07fae1f

Browse files
committed
escapeshellarg/escapeshellcmd: Throw TypeError instead of E_ERROR
1 parent 0d23952 commit 07fae1f

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

ext/opcache/Optimizer/zend_func_info.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ static const func_info_t func_infos[] = {
270270
F0("unlink", MAY_BE_FALSE | MAY_BE_TRUE),
271271
F1("exec", MAY_BE_FALSE | MAY_BE_STRING),
272272
F1("system", MAY_BE_FALSE | MAY_BE_STRING),
273-
F1("escapeshellcmd", MAY_BE_NULL | MAY_BE_STRING),
274-
F1("escapeshellarg", MAY_BE_NULL | MAY_BE_STRING),
273+
F1("escapeshellcmd", MAY_BE_STRING),
274+
F1("escapeshellarg", MAY_BE_STRING),
275275
F1("passthru", MAY_BE_NULL | MAY_BE_FALSE),
276276
F1("shell_exec", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
277277
#ifdef PHP_CAN_SUPPORT_PROC_OPEN

ext/standard/exec.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ PHP_FUNCTION(escapeshellcmd)
484484

485485
if (command_len) {
486486
if (command_len != strlen(command)) {
487-
php_error_docref(NULL, E_ERROR, "Input string contains NULL bytes");
487+
zend_type_error("Input string contains NULL bytes");
488488
return;
489489
}
490490
RETVAL_STR(php_escape_shell_cmd(command));
@@ -505,13 +505,12 @@ PHP_FUNCTION(escapeshellarg)
505505
Z_PARAM_STRING(argument, argument_len)
506506
ZEND_PARSE_PARAMETERS_END();
507507

508-
if (argument) {
509-
if (argument_len != strlen(argument)) {
510-
php_error_docref(NULL, E_ERROR, "Input string contains NULL bytes");
511-
return;
512-
}
513-
RETVAL_STR(php_escape_shell_arg(argument));
508+
if (argument_len != strlen(argument)) {
509+
zend_type_error("Input string contains NULL bytes");
510+
return;
514511
}
512+
513+
RETVAL_STR(php_escape_shell_arg(argument));
515514
}
516515
/* }}} */
517516

ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ escapeshellarg("hello\0world");
77
?>
88
===DONE===
99
--EXPECTF--
10-
Fatal error: escapeshellarg(): Input string contains NULL bytes in %s on line %d
10+
Fatal error: Uncaught TypeError: Input string contains NULL bytes in %s:%d
11+
Stack trace:
12+
#0 %s(%d): escapeshellarg('hello\x00world')
13+
#1 {main}
14+
thrown in %s on line %d

ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ escapeshellcmd("hello\0world");
77
?>
88
===DONE===
99
--EXPECTF--
10-
Fatal error: escapeshellcmd(): Input string contains NULL bytes in %s on line %d
10+
Fatal error: Uncaught TypeError: Input string contains NULL bytes in %s:%d
11+
Stack trace:
12+
#0 %s(%d): escapeshellcmd('hello\x00world')
13+
#1 {main}
14+
thrown in %s on line %d

0 commit comments

Comments
 (0)