]> granicus.if.org Git - php/commitdiff
Fix leak in DatePeriod construction with invalid format
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 30 Jan 2020 10:13:04 +0000 (11:13 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 30 Jan 2020 10:13:04 +0000 (11:13 +0100)
Same issue as I fixed in DateInterval construction before.

ext/date/php_date.c
ext/date/tests/date_interval_bad_format_leak.phpt

index 8b1bda20f0b92d36be75451420150d0f50f1d005..2ac5a30d937ed2daa435114afc37037d54370919 100644 (file)
@@ -4266,6 +4266,9 @@ static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_
        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 {
                *st = b;
                *et = e;
index 9d8af25ea4d4ce2ef91f97994b029a6c1731f79d..d15bf57b3f0100dcb4382a1d103ca048cccb8953 100644 (file)
@@ -9,6 +9,13 @@ try {
     echo $e->getMessage(), "\n";
 }
 
+try {
+    $perid = new DatePeriod('P3"D');
+} catch (Exception $e) {
+    echo $e->getMessage(), "\n";
+}
+
 ?>
 --EXPECT--
 DateInterval::__construct(): Unknown or bad format (P3"D)
+DatePeriod::__construct(): Unknown or bad format (P3"D)