1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3'

* PHP-8.3:
  Fix passing non-finite timeout values in stream functions
This commit is contained in:
Niels Dossche
2024-07-22 17:53:00 +02:00
2 changed files with 37 additions and 0 deletions

View File

@@ -124,6 +124,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);
@@ -276,6 +279,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