Skip to content

Commit 8df5133

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-14732: date_sun_info() fails for non-finite values
2 parents eaa2b61 + f9453a8 commit 8df5133

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ PHP NEWS
2727
- Date:
2828
. Fixed bug GH-16454 (Unhandled INF in date_sunset() with tiny $utcOffset).
2929
(cmb)
30+
. Fixed bug GH-14732 (date_sun_info() fails for non-finite values). (cmb)
3031

3132
- DBA:
3233
. Fixed bug GH-16390 (dba_open() can segfault for "pathless" streams). (cmb)

ext/date/php_date.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5299,6 +5299,10 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_s
52995299
}
53005300
altitude = 90 - zenith;
53015301

5302+
if (!zend_finite(latitude) || !zend_finite(longitude)) {
5303+
RETURN_FALSE;
5304+
}
5305+
53025306
/* Initialize time struct */
53035307
tzi = get_timezone_info();
53045308
if (!tzi) {
@@ -5376,6 +5380,15 @@ PHP_FUNCTION(date_sun_info)
53765380
Z_PARAM_DOUBLE(longitude)
53775381
ZEND_PARSE_PARAMETERS_END();
53785382

5383+
if (!zend_finite(latitude)) {
5384+
zend_argument_value_error(2, "must be finite");
5385+
RETURN_THROWS();
5386+
}
5387+
if (!zend_finite(longitude)) {
5388+
zend_argument_value_error(3, "must be finite");
5389+
RETURN_THROWS();
5390+
}
5391+
53795392
/* Initialize time struct */
53805393
tzi = get_timezone_info();
53815394
if (!tzi) {

ext/date/tests/gh14732.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-14732 (date_sun_info() fails for non-finite values)
3+
--FILE--
4+
<?php
5+
try {
6+
date_sun_info(1, NAN, 1);
7+
} catch (ValueError $ex) {
8+
echo $ex->getMessage(), "\n";
9+
}
10+
try {
11+
date_sun_info(1, -INF, 1);
12+
} catch (ValueError $ex) {
13+
echo $ex->getMessage(), "\n";
14+
}
15+
try {
16+
date_sun_info(1, 1, NAN);
17+
} catch (ValueError $ex) {
18+
echo $ex->getMessage(), "\n";
19+
}
20+
try {
21+
date_sun_info(1, 1, INF);
22+
} catch (ValueError $ex) {
23+
echo $ex->getMessage(), "\n";
24+
}
25+
var_dump(date_sunset(1, SUNFUNCS_RET_STRING, NAN, 1));
26+
var_dump(date_sunrise(1, SUNFUNCS_RET_STRING, 1, NAN));
27+
?>
28+
--EXPECTF--
29+
date_sun_info(): Argument #2 ($latitude) must be finite
30+
date_sun_info(): Argument #2 ($latitude) must be finite
31+
date_sun_info(): Argument #3 ($longitude) must be finite
32+
date_sun_info(): Argument #3 ($longitude) must be finite
33+
34+
Deprecated: Function date_sunset() is deprecated in %s on line %d
35+
bool(false)
36+
37+
Deprecated: Function date_sunrise() is deprecated in %s on line %d
38+
bool(false)

0 commit comments

Comments
 (0)