]> granicus.if.org Git - php/commitdiff
escapeshellarg/escapeshellcmd: Throw TypeError instead of E_ERROR
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 29 May 2019 14:57:16 +0000 (16:57 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 29 May 2019 14:57:53 +0000 (16:57 +0200)
ext/opcache/Optimizer/zend_func_info.c
ext/standard/exec.c
ext/standard/tests/general_functions/escapeshellarg_bug71039.phpt
ext/standard/tests/general_functions/escapeshellcmd_bug71039.phpt

index b6e970b506dc347c678bbe2e0ed11a834d23c9e4..651920c3cf62f4719a18db955eb139bf6b263cb6 100644 (file)
@@ -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
index 8ca0c9c6ae8ed8af134560500f248c47d840a73b..d5ab66daea86ba88a06ab57951c3a3b040b05c0d 100644 (file)
@@ -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));
 }
 /* }}} */
 
index cbb3f6fcc48a179d31e81e6a1209a9668cb6a681..b6bc828a87bef55acd75e81a2b2697a63c1b28ab 100644 (file)
@@ -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
index 0a4d7eacff209fffbe6ae02b0e960fbf34428bbf..7ce31fb8ddd6254db5716fc9a76536f16726563a 100644 (file)
@@ -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