Skip to content

Commit a0e1e08

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix passing non-finite timeout values in stream functions
2 parents b2963e9 + fdcfd62 commit a0e1e08

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PHP NEWS
2020
- Soap:
2121
. Fixed bug #55639 (Digest autentication dont work). (nielsdos)
2222

23+
- Standard:
24+
. Fix passing non-finite timeout values in stream functions. (nielsdos)
25+
2326
- Streams:
2427
. Fixed bug GH-15028 (Memory leak in ext/phar/stream.c). (nielsdos)
2528
. Fixed bug GH-15034 (Integer overflow on stream_notification_callback

ext/standard/streamsfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ PHP_FUNCTION(stream_socket_client)
127127

128128
if (timeout_is_null) {
129129
timeout = (double)FG(default_socket_timeout);
130+
} else if (!zend_finite(timeout)) {
131+
zend_argument_value_error(4, "must be a finite value");
132+
RETURN_THROWS();
130133
}
131134

132135
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
@@ -279,6 +282,9 @@ PHP_FUNCTION(stream_socket_accept)
279282

280283
if (timeout_is_null) {
281284
timeout = (double)FG(default_socket_timeout);
285+
} else if (!zend_finite(timeout)) {
286+
zend_argument_value_error(2, "must be a finite value");
287+
RETURN_THROWS();
282288
}
283289

284290
php_stream_from_zval(stream, zstream);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Non-finite timeout values in stream functions
3+
--FILE--
4+
<?php
5+
$socket = stream_socket_server("tcp://0.0.0.0:14781", $errno, $errstr);
6+
foreach ([NAN, -NAN, INF, -INF] as $value) {
7+
try {
8+
stream_socket_accept($socket, $value);
9+
} catch (ValueError $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
}
13+
fclose($socket);
14+
15+
foreach ([NAN, -NAN, INF, -INF] as $value) {
16+
try {
17+
stream_socket_client("tcp://0.0.0.0:14781", timeout: $value);
18+
} catch (ValueError $e) {
19+
echo $e->getMessage(), "\n";
20+
}
21+
}
22+
?>
23+
--EXPECT--
24+
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
25+
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
26+
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
27+
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
28+
stream_socket_client(): Argument #4 ($timeout) must be a finite value
29+
stream_socket_client(): Argument #4 ($timeout) must be a finite value
30+
stream_socket_client(): Argument #4 ($timeout) must be a finite value
31+
stream_socket_client(): Argument #4 ($timeout) must be a finite value

0 commit comments

Comments
 (0)