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

Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Fix GH-14732: date_sun_info() fails for non-finite values
This commit is contained in:
Christoph M. Becker
2024-11-01 23:47:01 +01:00
3 changed files with 52 additions and 0 deletions

1
NEWS
View File

@@ -27,6 +27,7 @@ PHP NEWS
- Date:
. Fixed bug GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset).
(cmb)
. Fixed bug GH-14732 (date_sun_info() fails for non-finite values). (cmb)
- DBA:
. Fixed bug GH-16390 (dba_open() can segfault for "pathless" streams). (cmb)

View File

@@ -5299,6 +5299,10 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_s
}
altitude = 90 - zenith;
if (!zend_finite(latitude) || !zend_finite(longitude)) {
RETURN_FALSE;
}
/* Initialize time struct */
tzi = get_timezone_info();
if (!tzi) {
@@ -5376,6 +5380,15 @@ PHP_FUNCTION(date_sun_info)
Z_PARAM_DOUBLE(longitude)
ZEND_PARSE_PARAMETERS_END();
if (!zend_finite(latitude)) {
zend_argument_value_error(2, "must be finite");
RETURN_THROWS();
}
if (!zend_finite(longitude)) {
zend_argument_value_error(3, "must be finite");
RETURN_THROWS();
}
/* Initialize time struct */
tzi = get_timezone_info();
if (!tzi) {

View File

@@ -0,0 +1,38 @@
--TEST--
GH-14732 (date_sun_info() fails for non-finite values)
--FILE--
<?php
try {
date_sun_info(1, NAN, 1);
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
try {
date_sun_info(1, -INF, 1);
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
try {
date_sun_info(1, 1, NAN);
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
try {
date_sun_info(1, 1, INF);
} catch (ValueError $ex) {
echo $ex->getMessage(), "\n";
}
var_dump(date_sunset(1, SUNFUNCS_RET_STRING, NAN, 1));
var_dump(date_sunrise(1, SUNFUNCS_RET_STRING, 1, NAN));
?>
--EXPECTF--
date_sun_info(): Argument #2 ($latitude) must be finite
date_sun_info(): Argument #2 ($latitude) must be finite
date_sun_info(): Argument #3 ($longitude) must be finite
date_sun_info(): Argument #3 ($longitude) must be finite
Deprecated: Function date_sunset() is deprecated in %s on line %d
bool(false)
Deprecated: Function date_sunrise() is deprecated in %s on line %d
bool(false)