]> granicus.if.org Git - php/commitdiff
Fix rel_date leak on DateInterval construction failure
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 28 Jan 2020 12:11:49 +0000 (13:11 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 28 Jan 2020 12:11:49 +0000 (13:11 +0100)
ext/date/php_date.c
ext/date/tests/date_interval_bad_format_leak.phpt [new file with mode: 0644]

index 0f6432b1a79f9ca2ae8130b14dea6206604aaab4..8b1bda20f0b92d36be75451420150d0f50f1d005 100644 (file)
@@ -3838,6 +3838,9 @@ static int date_interval_initialize(timelib_rel_time **rt, /*const*/ char *forma
        if (errors->error_count > 0) {
                php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s)", format);
                retval = FAILURE;
+               if (p) {
+                       timelib_rel_time_dtor(p);
+               }
        } else {
                if(p) {
                        *rt = p;
diff --git a/ext/date/tests/date_interval_bad_format_leak.phpt b/ext/date/tests/date_interval_bad_format_leak.phpt
new file mode 100644 (file)
index 0000000..9d8af25
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+DateInterval with bad format should not leak period
+--FILE--
+<?php
+
+try {
+    $interval = new DateInterval('P3"D');
+} catch (Exception $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+DateInterval::__construct(): Unknown or bad format (P3"D)