From: Máté Kocsis Date: Fri, 20 Dec 2019 16:53:53 +0000 (+0100) Subject: Promote warning to exception for proc_open() when null byte is encountered X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eff56f83af27c7bf230fc5f62ae2d53c1d092972;p=php Promote warning to exception for proc_open() when null byte is encountered GH-5004 --- diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index 85bd2c9f57..3871dcc201 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -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; } diff --git a/ext/standard/tests/general_functions/proc_open_array.phpt b/ext/standard/tests/general_functions/proc_open_array.phpt index 99e1cc56cb..b2ab4d8c9f 100644 --- a/ext/standard/tests/general_functions/proc_open_array.phpt +++ b/ext/standard/tests/general_functions/proc_open_array.phpt @@ -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!