From 0814f2a770ab44575a95ee17a097708f44d173b1 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 29 Jun 2024 06:46:14 +0100 Subject: [PATCH] Fix GH-14709 overflow on recurrences for DatePeriod::__construct --- ext/date/php_date.c | 6 +++--- ...eriod_wrong_recurrence_on_constructor.phpt | 6 +++--- ext/date/tests/gh14709.phpt | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 ext/date/tests/gh14709.phpt diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 4e1ff217b5c16..250f8ad445103 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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(); } @@ -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; diff --git a/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt b/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt index f2e121db389a3..4de0a1f8db73a 100644 --- a/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt +++ b/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt @@ -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 diff --git a/ext/date/tests/gh14709.phpt b/ext/date/tests/gh14709.phpt new file mode 100644 index 0000000000000..8bc402d185110 --- /dev/null +++ b/ext/date/tests/gh14709.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug GH-14709 overflow on reccurences parameter +--SKIPIF-- + +--FILE-- +getMessage(); +} +?> +--EXPECTF-- +DatePeriod::__construct(): Recurrence count must be between 1 and %d