Skip to content

Commit ee789d2

Browse files
committed
changes from feedback
1 parent 46ab0e1 commit ee789d2

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

ext/date/php_date.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,8 @@ PHP_METHOD(DatePeriod, __construct)
47434743
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
47444744
dpobj->current = NULL;
47454745

4746+
const zend_long max_recurrences = (INT_MAX - 8);
4747+
47464748
if (isostr) {
47474749
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len)) {
47484750
RETURN_THROWS();
@@ -4808,9 +4810,9 @@ PHP_METHOD(DatePeriod, __construct)
48084810
}
48094811
}
48104812

4811-
if (dpobj->end == NULL && (recurrences < 1 || ZEND_LONG_INT_OVFL(recurrences))) {
4813+
if (dpobj->end == NULL && (recurrences < 1 || recurrences > max_recurrences)) {
48124814
zend_string *func = get_active_function_or_method_name();
4813-
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d", ZSTR_VAL(func), INT_MAX);
4815+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be greater or equal to 1 and lower than " ZEND_LONG_FMT, ZSTR_VAL(func), max_recurrences + 1);
48144816
zend_string_release(func);
48154817
RETURN_THROWS();
48164818
}
@@ -4821,9 +4823,9 @@ PHP_METHOD(DatePeriod, __construct)
48214823

48224824
recurrences += dpobj->include_start_date + dpobj->include_end_date;
48234825

4824-
if (UNEXPECTED(ZEND_LONG_INT_OVFL(recurrences))) {
4826+
if (UNEXPECTED(recurrences > max_recurrences)) {
48254827
zend_string *func = get_active_function_or_method_name();
4826-
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be between 1 and %d (including options)", ZSTR_VAL(func), INT_MAX);
4828+
zend_throw_exception_ex(NULL, 0, "%s(): Recurrence count must be greater or equal to 1 and lower than " ZEND_LONG_FMT " (including options)", ZSTR_VAL(func), max_recurrences + 1);
48274829
zend_string_release(func);
48284830
RETURN_THROWS();
48294831
}

ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ try {
1616

1717
?>
1818
--EXPECTF--
19-
DatePeriod::__construct(): Recurrence count must be between 1 and %d
20-
DatePeriod::__construct(): Recurrence count must be between 1 and %d
19+
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
20+
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d

ext/date/tests/gh14709.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ $start = new DateTime('2018-12-31 00:00:00');
1010
$interval = new DateInterval('P1M');
1111

1212
try {
13-
new DatePeriod($start, $interval, PHP_INT_MAX);
13+
new DatePeriod($start, $interval, 2147483640);
1414
} catch (Exception $e) {
1515
echo $e->getMessage() . PHP_EOL;
1616
}
1717

1818
try {
19-
new DatePeriod($start, $interval, 2147483647, DatePeriod::EXCLUDE_START_DATE | DatePeriod::INCLUDE_END_DATE);
19+
new DatePeriod($start, $interval, 2147483639, DatePeriod::EXCLUDE_START_DATE | DatePeriod::INCLUDE_END_DATE);
2020
} catch (Exception $e) {
2121
echo $e->getMessage();
2222
}
2323
?>
2424
--EXPECTF--
25-
DatePeriod::__construct(): Recurrence count must be between 1 and %d
26-
DatePeriod::__construct(): Recurrence count must be between 1 and %d (including options)
25+
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d
26+
DatePeriod::__construct(): Recurrence count must be greater or equal to 1 and lower than %d (including options)

0 commit comments

Comments
 (0)