Skip to content

Commit c9fa98a

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
2 parents 4d7ccbb + d9ff5e0 commit c9fa98a

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ PHP NEWS
3636
- SQLite3:
3737
. Fixed bug GH-9032 (SQLite3 authorizer crashes on NULL values). (cmb)
3838

39+
- Streams:
40+
. Fixed bug GH-8472 (The resource returned by stream_socket_accept may have
41+
incorrect metadata). (Jakub Zelenka)
42+
3943
04 Aug 2022, PHP 8.1.9
4044

4145
- CLI:

ext/openssl/xp_ssl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,10 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_
22942294
memcpy(clisockdata, sock, sizeof(clisockdata->s));
22952295

22962296
clisockdata->s.socket = clisock;
2297+
#ifdef __linux__
2298+
/* O_NONBLOCK is not inherited on Linux */
2299+
clisockdata->s.is_blocked = 1;
2300+
#endif
22972301

22982302
xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
22992303
if (xparam->outputs.client) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-8472: The resource returned by stream_socket_accept may have incorrect metadata
3+
--FILE--
4+
<?php
5+
function setNonBlocking($stream)
6+
{
7+
$block = stream_get_meta_data($stream)['blocked'];
8+
if ($block) {
9+
stream_set_blocking($stream, false);
10+
}
11+
}
12+
13+
$server = stream_socket_server("tcp://127.0.0.1:9100");
14+
setNonBlocking($server);
15+
16+
$client = stream_socket_client("tcp://127.0.0.1:9100");
17+
18+
$res = stream_socket_accept($server);
19+
stream_set_timeout($res, 1);
20+
setNonBlocking($res);
21+
22+
fwrite($client, str_repeat('0', 5));
23+
24+
$read = [$res];
25+
$write = [];
26+
$except = [];
27+
28+
if (stream_select($read, $write, $except, 1)) {
29+
var_dump(fread($res, 4));
30+
var_dump(fread($res, 4));
31+
}
32+
?>
33+
--EXPECT--
34+
string(4) "0000"
35+
string(1) "0"

main/streams/xp_socket.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
841841

842842
memcpy(clisockdata, sock, sizeof(*clisockdata));
843843
clisockdata->socket = clisock;
844+
#ifdef __linux__
845+
/* O_NONBLOCK is not inherited on Linux */
846+
clisockdata->is_blocked = 1;
847+
#endif
844848

845849
xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
846850
if (xparam->outputs.client) {

0 commit comments

Comments
 (0)