Skip to content

Commit 5e617d0

Browse files
authored
proc_open: reject array with empty command name (#10559)
1 parent fa1a7f0 commit 5e617d0

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

UPGRADING

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ PHP 8.3 UPGRADE NOTES
7373
. strtok() raises a warning in the case token is not provided when starting tokenization.
7474
. password_hash() will now chain the underlying Random\RandomException
7575
as the ValueError’s $previous Exception when salt generation fails.
76+
. proc_open() $command array must now have at least one non empty element.
7677

7778
========================================
7879
6. New Functions

ext/standard/proc_open.c

+6
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ static zend_string *get_valid_arg_string(zval *zv, int elem_num) {
475475
return NULL;
476476
}
477477

478+
if (elem_num == 1 && ZSTR_LEN(str) == 0) {
479+
zend_value_error("First element must contain a non-empty program name");
480+
zend_string_release(str);
481+
return NULL;
482+
}
483+
478484
if (strlen(ZSTR_VAL(str)) != ZSTR_LEN(str)) {
479485
zend_value_error("Command array element %d contains a null byte", elem_num);
480486
zend_string_release(str);

ext/standard/tests/general_functions/proc_open_array.phpt

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ try {
3131
echo $exception->getMessage() . "\n";
3232
}
3333

34+
echo "\nEmpty program name:\n";
35+
try {
36+
proc_open([""], $ds, $pipes);
37+
} catch (ValueError $exception) {
38+
echo $exception->getMessage() . "\n";
39+
}
40+
3441
echo "\nBasic usage:\n";
3542
$proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes);
3643
fpassthru($pipes[1]);
@@ -76,6 +83,9 @@ Command array element 1 contains a null byte
7683
Nul byte in argument:
7784
Command array element 2 contains a null byte
7885

86+
Empty program name:
87+
First element must contain a non-empty program name
88+
7989
Basic usage:
8090
Hello World!
8191

0 commit comments

Comments
 (0)