Skip to content

Commit 32d55f7

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-9017: php_stream_sock_open_from_socket could return NULL
2 parents aa1fa8c + 3b7babf commit 32d55f7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ PHP NEWS
4343
- Standard:
4444
. Fixed the crypt_sha256/512 api build with clang > 12. (David Carlier)
4545
. Uses CCRandomGenerateBytes instead of arc4random_buf on macOs. (David Carlier).
46+
. Fixed bug GH-9017 (php_stream_sock_open_from_socket could return NULL).
47+
(Heiko Weber)
4648

4749
07 Jul 2022, PHP 8.1.8
4850

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)