Skip to content

Commit

Permalink
Fixed bug #77909: DatePeriod::__construct() with invalid recurrence c…
Browse files Browse the repository at this point in the history
…ount value

Improve error message on invalid reccurence count

Adding test when reccurence is -1
  • Loading branch information
nyamsprod authored and derickr committed Apr 17, 2019
1 parent 6fe75f9 commit 7b1a4e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7b1a4e2

Please sign in to comment.