Skip to content

Fix GH-14732: date_sun_info() fails for non-finite values #16497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -5111,6 +5111,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) {
Expand Down Expand Up @@ -5188,6 +5192,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) {
Expand Down
38 changes: 38 additions & 0 deletions ext/date/tests/gh14732.phpt
Original file line number Diff line number Diff line change
@@ -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)
Loading