summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-01-30 12:16:43 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-01-30 12:16:56 +0100
commit494615fcb8c1fb5984e0e7d666e51a2dfc6bee55 (patch)
treea5854e4fbbf029889342382310304abc6db3a017 /ext/date
parent6ccd67577696b9c8bf3d88b521320720771dfc09 (diff)
downloadphp-git-494615fcb8c1fb5984e0e7d666e51a2dfc6bee55.tar.gz
Fix leak in DateTimeImmutable::modify()
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/php_date.c1
-rw-r--r--ext/date/tests/DateTimeImmutable_modify_invalid_format.phpt12
2 files changed, 13 insertions, 0 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 785c1b222e..bec60aab6d 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -3297,6 +3297,7 @@ PHP_METHOD(DateTimeImmutable, modify)
date_clone_immutable(object, &new_object);
if (!php_date_modify(&new_object, modify, modify_len)) {
+ zval_ptr_dtor(&new_object);
RETURN_FALSE;
}
diff --git a/ext/date/tests/DateTimeImmutable_modify_invalid_format.phpt b/ext/date/tests/DateTimeImmutable_modify_invalid_format.phpt
new file mode 100644
index 0000000000..3386f725ac
--- /dev/null
+++ b/ext/date/tests/DateTimeImmutable_modify_invalid_format.phpt
@@ -0,0 +1,12 @@
+--TEST--
+DateTimeImmutable::modify() with invalid format
+--FILE--
+<?php
+
+$datetime = new DateTimeImmutable;
+var_dump($datetime->modify(''));
+
+?>
+--EXPECTF--
+Warning: DateTimeImmutable::modify(): Failed to parse time string () at position 0 ( in %s on line %d
+bool(false)