]> granicus.if.org Git - php/commitdiff
Promote warning to exception for proc_open() when null byte is encountered
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 20 Dec 2019 16:53:53 +0000 (17:53 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 20 Dec 2019 16:54:12 +0000 (17:54 +0100)
GH-5004

ext/standard/proc_open.c
ext/standard/tests/general_functions/proc_open_array.phpt

index 85bd2c9f57c8e00a5dfc43a7267a017d2b379815..3871dcc201768966fa82c66f7acde5a097652338 100644 (file)
@@ -401,8 +401,7 @@ static zend_string *get_valid_arg_string(zval *zv, int elem_num) {
        }
 
        if (strlen(ZSTR_VAL(str)) != ZSTR_LEN(str)) {
-               php_error_docref(NULL, E_WARNING,
-                       "Command array element %d contains a null byte", elem_num);
+               zend_value_error("Command array element %d contains a null byte", elem_num);
                zend_string_release(str);
                return NULL;
        }
index 99e1cc56cb4d355713980299708296ee8aeaf4e9..b2ab4d8c9f057c2fd85bbc919846ab580c4d52d9 100644 (file)
@@ -17,11 +17,19 @@ try {
     echo $exception->getMessage() . "\n";
 }
 
-echo "\nNul byte in program name:";
-var_dump(proc_open(["php\0oops"], $ds, $pipes));
+echo "\nNul byte in program name:\n";
+try {
+    proc_open(["php\0oops"], $ds, $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
-echo "\nNul byte in argument:";
-var_dump(proc_open(["php", "arg\0oops"], $ds, $pipes));
+echo "\nNul byte in argument:\n";
+try {
+    proc_open(["php", "arg\0oops"], $ds, $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
 echo "\nBasic usage:\n";
 $proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes);
@@ -58,17 +66,15 @@ fpassthru($pipes[1]);
 proc_close($proc);
 
 ?>
---EXPECTF--
+--EXPECT--
 Empty command array:
 Command array must have at least one element
 
 Nul byte in program name:
-Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d
-bool(false)
+Command array element 1 contains a null byte
 
 Nul byte in argument:
-Warning: proc_open(): Command array element 2 contains a null byte in %s on line %d
-bool(false)
+Command array element 2 contains a null byte
 
 Basic usage:
 Hello World!