From: Nikita Popov Date: Wed, 29 May 2019 14:57:16 +0000 (+0200) Subject: escapeshellarg/escapeshellcmd: Throw TypeError instead of E_ERROR X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=07fae1fd6efec09dcd928760147682cd6a6aa354;p=php escapeshellarg/escapeshellcmd: Throw TypeError instead of E_ERROR --- diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index b6e970b506..651920c3cf 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -270,8 +270,8 @@ static const func_info_t func_infos[] = { F0("unlink", MAY_BE_FALSE | MAY_BE_TRUE), F1("exec", MAY_BE_FALSE | MAY_BE_STRING), F1("system", MAY_BE_FALSE | MAY_BE_STRING), - F1("escapeshellcmd", MAY_BE_NULL | MAY_BE_STRING), - F1("escapeshellarg", MAY_BE_NULL | MAY_BE_STRING), + F1("escapeshellcmd", MAY_BE_STRING), + F1("escapeshellarg", MAY_BE_STRING), F1("passthru", MAY_BE_NULL | MAY_BE_FALSE), F1("shell_exec", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), #ifdef PHP_CAN_SUPPORT_PROC_OPEN diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 8ca0c9c6ae..d5ab66daea 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -484,7 +484,7 @@ PHP_FUNCTION(escapeshellcmd) if (command_len) { if (command_len != strlen(command)) { - php_error_docref(NULL, E_ERROR, "Input string contains NULL bytes"); + zend_type_error("Input string contains NULL bytes"); return; } RETVAL_STR(php_escape_shell_cmd(command)); @@ -505,13 +505,12 @@ PHP_FUNCTION(escapeshellarg) Z_PARAM_STRING(argument, argument_len) ZEND_PARSE_PARAMETERS_END(); - if (argument) { - if (argument_len != strlen(argument)) { - php_error_docref(NULL, E_ERROR, "Input string contains NULL bytes"); - return; - } - RETVAL_STR(php_escape_shell_arg(argument)); + if (argument_len != strlen(argument)) { + zend_type_error("Input string contains NULL bytes"); + return; } + + RETVAL_STR(php_escape_shell_arg(argument)); } /* }}} */ diff --git a/ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt b/ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt index cbb3f6fcc4..b6bc828a87 100644 --- a/ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt +++ b/ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt @@ -7,4 +7,8 @@ escapeshellarg("hello\0world"); ?> ===DONE=== --EXPECTF-- -Fatal error: escapeshellarg(): Input string contains NULL bytes in %s on line %d +Fatal error: Uncaught TypeError: Input string contains NULL bytes in %s:%d +Stack trace: +#0 %s(%d): escapeshellarg('hello\x00world') +#1 {main} + thrown in %s on line %d diff --git a/ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt b/ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt index 0a4d7eacff..7ce31fb8dd 100644 --- a/ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt +++ b/ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt @@ -7,4 +7,8 @@ escapeshellcmd("hello\0world"); ?> ===DONE=== --EXPECTF-- -Fatal error: escapeshellcmd(): Input string contains NULL bytes in %s on line %d +Fatal error: Uncaught TypeError: Input string contains NULL bytes in %s:%d +Stack trace: +#0 %s(%d): escapeshellcmd('hello\x00world') +#1 {main} + thrown in %s on line %d