summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--ext/date/php_date.c4
-rw-r--r--ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt19
3 files changed, 27 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 4cb9b1ca5b..89276908bb 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,10 @@ PHP NEWS
. Fixed bug #77794 (Incorrect Date header format in built-in server).
(kelunik)
+- Date:
+ . Fixed bug #77909 (DatePeriod::__construct() with invalid recurrence count
+ value). (Ignace Nyamagana Butera)
+
- Interbase:
. Fixed bug #72175 (Impossibility of creating multiple connections to
Interbase with php 7.x). (Nikita)
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 9b37a9e3c1..f47ba5bc54 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4645,6 +4645,10 @@ PHP_METHOD(DatePeriod, __construct)
dpobj->end = clone;
}
}
+
+ if (dpobj->end == NULL && recurrences < 1) {
+ php_error_docref(NULL, E_WARNING, "The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences);
+ }
/* options */
dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
diff --git a/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt b/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt
new file mode 100644
index 0000000000..715ea63dc9
--- /dev/null
+++ b/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt
@@ -0,0 +1,19 @@
+--TEST--
+DatePeriod: Test wrong recurrence parameter on __construct
+--FILE--
+<?php
+try {
+ new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), 0);
+} catch (Exception $exception) {
+ echo $exception->getMessage(), "\n";
+}
+
+try {
+ new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'),-1);
+} catch (Exception $exception) {
+ echo $exception->getMessage(), "\n";
+}
+?>
+--EXPECTF--
+DatePeriod::__construct(): The recurrence count '0' is invalid. Needs to be > 0
+DatePeriod::__construct(): The recurrence count '-1' is invalid. Needs to be > 0