]> granicus.if.org Git - php/commitdiff
Fix leak on failed DatePeriod initialization
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 27 Aug 2020 10:54:43 +0000 (12:54 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 27 Aug 2020 10:54:43 +0000 (12:54 +0200)
We need to free not only p here, but also b and e.

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

index 0892439a0671b63609bbaf12a1bacf9b1a6b5736..43aa2ba637e6a5a4d752408d756046154d4c1d86 100644 (file)
@@ -4077,6 +4077,12 @@ 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 (b) {
+                       timelib_time_dtor(b);
+               }
+               if (e) {
+                       timelib_time_dtor(e);
+               }
                if (p) {
                        timelib_rel_time_dtor(p);
                }
index d15bf57b3f0100dcb4382a1d103ca048cccb8953..da6982c9bedb2e10d14f9a3b1bb51813430f144c 100644 (file)
@@ -15,7 +15,14 @@ try {
     echo $e->getMessage(), "\n";
 }
 
+try {
+    new DatePeriod('2008-03-01T12:00:00Z1');
+} catch (Exception $e) {
+    echo $e->getMessage(), "\n";
+}
+
 ?>
 --EXPECT--
 DateInterval::__construct(): Unknown or bad format (P3"D)
 DatePeriod::__construct(): Unknown or bad format (P3"D)
+DatePeriod::__construct(): Unknown or bad format (2008-03-01T12:00:00Z1)