Skip to content

Commit 340024e

Browse files
committed
Fix GH-9017: php_stream_sock_open_from_socket could return NULL
1 parent b44a17c commit 340024e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ext/standard/streamsfuncs.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,22 @@ PHP_FUNCTION(stream_socket_pair)
6767
RETURN_FALSE;
6868
}
6969

70-
array_init(return_value);
71-
72-
s1 = php_stream_sock_open_from_socket(pair[0], 0);
73-
s2 = php_stream_sock_open_from_socket(pair[1], 0);
70+
s1 = php_stream_sock_open_from_socket(pair[0], 0);
71+
if (s1 == NULL) {
72+
close(pair[0]);
73+
close(pair[1]);
74+
php_error_docref(NULL, E_WARNING, "Failed to open stream from socketpair");
75+
RETURN_FALSE;
76+
}
77+
s2 = php_stream_sock_open_from_socket(pair[1], 0);
78+
if (s2 == NULL) {
79+
php_stream_free(s1, PHP_STREAM_FREE_CLOSE));
80+
close(pair[1]);
81+
php_error_docref(NULL, E_WARNING, "Failed to open stream from socketpair");
82+
RETURN_FALSE;
83+
}
84+
85+
array_init(return_value);
7486

7587
/* set the __exposed flag.
7688
* php_stream_to_zval() does, add_next_index_resource() does not */

0 commit comments

Comments
 (0)