summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorDerick Rethans <github@derickrethans.nl>2019-04-17 09:39:18 +0100
committerDerick Rethans <github@derickrethans.nl>2019-04-17 09:40:18 +0100
commit6088713216a176267c8eababbbd33736840028a6 (patch)
tree382144acd1b232faa56d517ab6b91bf2247d8ec7 /ext/date
parentec8457d982512e58db6191b7c09a1513b58b79ac (diff)
parent7b1a4e24008f34a76c343ece735953ad5124e09f (diff)
downloadphp-git-6088713216a176267c8eababbbd33736840028a6.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/php_date.c4
-rw-r--r--ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt19
2 files changed, 23 insertions, 0 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 541fdafea3..6bc5936a74 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4639,6 +4639,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