Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions ext/calendar/dow.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ int DayOfWeek(
{
int dow;

if ((sdn + 1) > INT_MAX) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zend_long can be the same as int; in which case this check is removed by the compiler because it'll be UB.
Note that you can just change the formula and the if-checks a bit because we're working in mod 7 to avoid the overflow; and avoid needing to check the overflow in the first place.

return (0);
}

dow = (sdn + 1) % 7;
if (dow >= 0) {
return (dow);
Expand Down
2 changes: 1 addition & 1 deletion ext/calendar/tests/bug53574_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ array(9) {
["year"]=>
int(0)
["dow"]=>
int(3)
int(0)
["abbrevdayname"]=>
string(3) "Wed"
["dayname"]=>
Expand Down
12 changes: 12 additions & 0 deletions ext/calendar/tests/gh16258.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-16258 (jddayofweek overflow on argument)
--EXTENSIONS--
calendar
--FILE--
<?php
jddayofweek(9223372036854775807, 1);
jddayofweek(-9223372036854775806, 1);
echo "DONE";
?>
--EXPECT--
DONE
Loading