Skip to content

Commit

Permalink
Fix phpGH-14709 overflow on reccurences for DatePeriod::__construct
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Jun 29, 2024
1 parent 42908f9 commit 8317de6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -4798,9 +4798,9 @@ PHP_METHOD(DatePeriod, __construct)
}
}

if (dpobj->end == NULL && recurrences < 1) {
if (dpobj->end == NULL && (recurrences < 1 || ZEND_LONG_INT_OVFL(recurrences))) {
zend_string *func = get_active_function_or_method_name();
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d", ZSTR_VAL(func), INT_MAX);
zend_string_release(func);
RETURN_THROWS();
}
Expand All @@ -4809,7 +4809,7 @@ PHP_METHOD(DatePeriod, __construct)
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE;

/* recurrrences */
/* recurrences */
dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;

dpobj->initialized = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ try {
}

?>
--EXPECT--
DatePeriod::__construct(): Recurrence count must be greater than 0
DatePeriod::__construct(): Recurrence count must be greater than 0
--EXPECTF--
DatePeriod::__construct(): Recurrence count must be between 1 and %d
DatePeriod::__construct(): Recurrence count must be between 1 and %d
19 changes: 19 additions & 0 deletions ext/date/tests/gh14709.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Bug GH-14709 overflow on reccurences parameter
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
<?php
$start = new DateTime('2018-12-31 00:00:00');
$interval = new DateInterval('P1M');

try {
new DatePeriod($start, $interval, PHP_INT_MAX);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
--EXPECTF--
DatePeriod::__construct(): Recurrence count must be between 1 and %d

0 comments on commit 8317de6

Please sign in to comment.