Skip to content

Commit 80197c5

Browse files
committed
Merge branch 'PHP-8.1'
2 parents 2650340 + c9fa98a commit 80197c5

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

ext/openssl/xp_ssl.c

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

22872287
clisockdata->s.socket = clisock;
2288+
#ifdef __linux__
2289+
/* O_NONBLOCK is not inherited on Linux */
2290+
clisockdata->s.is_blocked = 1;
2291+
#endif
22882292

22892293
xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
22902294
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
@@ -842,6 +842,10 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t
842842

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

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

0 commit comments

Comments
 (0)