Skip to content

Commit

Permalink
Merge branch 'PHP-8.0' into PHP-8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bukka committed Aug 7, 2022
2 parents 4d7ccbb + d9ff5e0 commit c9fa98a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -36,6 +36,10 @@ PHP NEWS
- SQLite3:
. Fixed bug GH-9032 (SQLite3 authorizer crashes on NULL values). (cmb)

- Streams:
. Fixed bug GH-8472 (The resource returned by stream_socket_accept may have
incorrect metadata). (Jakub Zelenka)

04 Aug 2022, PHP 8.1.9

- CLI:
Expand Down
4 changes: 4 additions & 0 deletions ext/openssl/xp_ssl.c
Expand Up @@ -2294,6 +2294,10 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_
memcpy(clisockdata, sock, sizeof(clisockdata->s));

clisockdata->s.socket = clisock;
#ifdef __linux__
/* O_NONBLOCK is not inherited on Linux */
clisockdata->s.is_blocked = 1;
#endif

xparam->outputs.client = php_stream_alloc_rel(stream->ops, clisockdata, NULL, "r+");
if (xparam->outputs.client) {
Expand Down
35 changes: 35 additions & 0 deletions ext/standard/tests/streams/gh8472.phpt
@@ -0,0 +1,35 @@
--TEST--
GH-8472: The resource returned by stream_socket_accept may have incorrect metadata
--FILE--
<?php
function setNonBlocking($stream)
{
$block = stream_get_meta_data($stream)['blocked'];
if ($block) {
stream_set_blocking($stream, false);
}
}

$server = stream_socket_server("tcp://127.0.0.1:9100");
setNonBlocking($server);

$client = stream_socket_client("tcp://127.0.0.1:9100");

$res = stream_socket_accept($server);
stream_set_timeout($res, 1);
setNonBlocking($res);

fwrite($client, str_repeat('0', 5));

$read = [$res];
$write = [];
$except = [];

if (stream_select($read, $write, $except, 1)) {
var_dump(fread($res, 4));
var_dump(fread($res, 4));
}
?>
--EXPECT--
string(4) "0000"
string(1) "0"
4 changes: 4 additions & 0 deletions main/streams/xp_socket.c
Expand Up @@ -841,6 +841,10 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t

memcpy(clisockdata, sock, sizeof(*clisockdata));
clisockdata->socket = clisock;
#ifdef __linux__
/* O_NONBLOCK is not inherited on Linux */
clisockdata->is_blocked = 1;
#endif

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

0 comments on commit c9fa98a

Please sign in to comment.