Skip to content

Commit eff56f8

Browse files
committed
Promote warning to exception for proc_open() when null byte is encountered
GH-5004
1 parent 1d6325f commit eff56f8

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

ext/standard/proc_open.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ static zend_string *get_valid_arg_string(zval *zv, int elem_num) {
401401
}
402402

403403
if (strlen(ZSTR_VAL(str)) != ZSTR_LEN(str)) {
404-
php_error_docref(NULL, E_WARNING,
405-
"Command array element %d contains a null byte", elem_num);
404+
zend_value_error("Command array element %d contains a null byte", elem_num);
406405
zend_string_release(str);
407406
return NULL;
408407
}

ext/standard/tests/general_functions/proc_open_array.phpt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ try {
1717
echo $exception->getMessage() . "\n";
1818
}
1919

20-
echo "\nNul byte in program name:";
21-
var_dump(proc_open(["php\0oops"], $ds, $pipes));
20+
echo "\nNul byte in program name:\n";
21+
try {
22+
proc_open(["php\0oops"], $ds, $pipes);
23+
} catch (ValueError $exception) {
24+
echo $exception->getMessage() . "\n";
25+
}
2226

23-
echo "\nNul byte in argument:";
24-
var_dump(proc_open(["php", "arg\0oops"], $ds, $pipes));
27+
echo "\nNul byte in argument:\n";
28+
try {
29+
proc_open(["php", "arg\0oops"], $ds, $pipes);
30+
} catch (ValueError $exception) {
31+
echo $exception->getMessage() . "\n";
32+
}
2533

2634
echo "\nBasic usage:\n";
2735
$proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes);
@@ -58,17 +66,15 @@ fpassthru($pipes[1]);
5866
proc_close($proc);
5967

6068
?>
61-
--EXPECTF--
69+
--EXPECT--
6270
Empty command array:
6371
Command array must have at least one element
6472

6573
Nul byte in program name:
66-
Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d
67-
bool(false)
74+
Command array element 1 contains a null byte
6875

6976
Nul byte in argument:
70-
Warning: proc_open(): Command array element 2 contains a null byte in %s on line %d
71-
bool(false)
77+
Command array element 2 contains a null byte
7278

7379
Basic usage:
7480
Hello World!

0 commit comments

Comments
 (0)