Skip to content

proc_open: reject array with empty command name #10559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/standard/proc_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ static zend_string *get_valid_arg_string(zval *zv, int elem_num) {
return NULL;
}

if (elem_num == 1 && ZSTR_LEN(str) == 0) {
zend_value_error("First element must contain a non-empty program name");
zend_string_release(str);
return NULL;
}

if (strlen(ZSTR_VAL(str)) != ZSTR_LEN(str)) {
zend_value_error("Command array element %d contains a null byte", elem_num);
zend_string_release(str);
Expand Down
10 changes: 10 additions & 0 deletions ext/standard/tests/general_functions/proc_open_array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ try {
echo $exception->getMessage() . "\n";
}

echo "\nEmpty program name:\n";
try {
proc_open([""], $ds, $pipes);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

echo "\nBasic usage:\n";
$proc = proc_open([$php, '-r', 'echo "Hello World!\n";'], $ds, $pipes);
fpassthru($pipes[1]);
Expand Down Expand Up @@ -76,6 +83,9 @@ Command array element 1 contains a null byte
Nul byte in argument:
Command array element 2 contains a null byte

Empty program name:
First element must contain a non-empty program name

Basic usage:
Hello World!

Expand Down