Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Fix passing non-finite timeout values in stream functions
This commit is contained in:
Niels Dossche 2024-07-22 17:52:53 +02:00
commit a0e1e085d8
No known key found for this signature in database
GPG Key ID: B8A8AD166DF0E2E5
3 changed files with 40 additions and 0 deletions

3
NEWS
View File

@ -20,6 +20,9 @@ PHP NEWS
- Soap:
. Fixed bug #55639 (Digest autentication dont work). (nielsdos)
- Standard:
. Fix passing non-finite timeout values in stream functions. (nielsdos)
- Streams:
. Fixed bug GH-15028 (Memory leak in ext/phar/stream.c). (nielsdos)
. Fixed bug GH-15034 (Integer overflow on stream_notification_callback

View File

@ -127,6 +127,9 @@ PHP_FUNCTION(stream_socket_client)
if (timeout_is_null) {
timeout = (double)FG(default_socket_timeout);
} else if (!zend_finite(timeout)) {
zend_argument_value_error(4, "must be a finite value");
RETURN_THROWS();
}
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
@ -279,6 +282,9 @@ PHP_FUNCTION(stream_socket_accept)
if (timeout_is_null) {
timeout = (double)FG(default_socket_timeout);
} else if (!zend_finite(timeout)) {
zend_argument_value_error(2, "must be a finite value");
RETURN_THROWS();
}
php_stream_from_zval(stream, zstream);

View File

@ -0,0 +1,31 @@
--TEST--
Non-finite timeout values in stream functions
--FILE--
<?php
$socket = stream_socket_server("tcp://0.0.0.0:14781", $errno, $errstr);
foreach ([NAN, -NAN, INF, -INF] as $value) {
try {
stream_socket_accept($socket, $value);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
}
fclose($socket);
foreach ([NAN, -NAN, INF, -INF] as $value) {
try {
stream_socket_client("tcp://0.0.0.0:14781", timeout: $value);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
stream_socket_accept(): Argument #2 ($timeout) must be a finite value
stream_socket_client(): Argument #4 ($timeout) must be a finite value
stream_socket_client(): Argument #4 ($timeout) must be a finite value
stream_socket_client(): Argument #4 ($timeout) must be a finite value
stream_socket_client(): Argument #4 ($timeout) must be a finite value