Skip to content

Fix GH-9017: php_stream_sock_open_from_socket could return NULL #9020

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
20 changes: 16 additions & 4 deletions ext/standard/streamsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,22 @@ PHP_FUNCTION(stream_socket_pair)
RETURN_FALSE;
}

array_init(return_value);

s1 = php_stream_sock_open_from_socket(pair[0], 0);
s2 = php_stream_sock_open_from_socket(pair[1], 0);
s1 = php_stream_sock_open_from_socket(pair[0], 0);
if (s1 == NULL) {
close(pair[0]);
close(pair[1]);
php_error_docref(NULL, E_WARNING, "Failed to open stream from socketpair");
RETURN_FALSE;
}
s2 = php_stream_sock_open_from_socket(pair[1], 0);
if (s2 == NULL) {
php_stream_free(s1, PHP_STREAM_FREE_CLOSE);
close(pair[1]);
php_error_docref(NULL, E_WARNING, "Failed to open stream from socketpair");
RETURN_FALSE;
}

array_init(return_value);

/* set the __exposed flag.
* php_stream_to_zval() does, add_next_index_resource() does not */
Expand Down