diff options
author | Máté Kocsis <kocsismate@woohoolabs.com> | 2019-12-20 17:53:53 +0100 |
---|---|---|
committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2019-12-20 17:54:12 +0100 |
commit | eff56f83af27c7bf230fc5f62ae2d53c1d092972 (patch) | |
tree | dd1fcca3de696854e0e513255e1d1076e385dfb3 | |
parent | 1d6325fb017236a3765ed2bcb306039576cbb189 (diff) | |
download | php-git-eff56f83af27c7bf230fc5f62ae2d53c1d092972.tar.gz |
Promote warning to exception for proc_open() when null byte is encountered
GH-5004
-rw-r--r-- | ext/standard/proc_open.c | 3 | ||||
-rw-r--r-- | ext/standard/tests/general_functions/proc_open_array.phpt | 24 |
2 files changed, 16 insertions, 11 deletions
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! |