Skip to content

Commit 3b7babf

Browse files
hwdecmb69
authored andcommitted
Fix phpGH-9017: php_stream_sock_open_from_socket could return NULL
Closes phpGH-9020.
1 parent a670d2b commit 3b7babf

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2022, PHP 8.0.23
44

5+
- Standard:
6+
. Fixed bug GH-9017 (php_stream_sock_open_from_socket could return NULL).
7+
(Heiko Weber)
58

69
04 Aug 2022, PHP 8.0.22
710

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)