]> granicus.if.org Git - php/commitdiff
Fix #80223: imap_mail_compose() leaks envelope on malformed bodies
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 12 Oct 2020 11:26:38 +0000 (13:26 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 12 Oct 2020 13:08:30 +0000 (15:08 +0200)
We have to clean up even on failure.

Closes GH-6322.

NEWS
ext/imap/php_imap.c
ext/imap/tests/bug80223.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 72f731aef19528961f36b9961a17872f6cbe0665..368199ed74cbef8dac414c3e49edd4b7d48b051d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP                                                                        NEWS
   . Fixed bug #80213 (imap_mail_compose() segfaults on certain $bodies). (cmb)
   . Fixed bug #80215 (imap_mail_compose() may modify by-val parameters). (cmb)
   . Fixed bug #80220 (imap_mail_compose() may leak memory). (cmb)
+  . Fixed bug #80223 (imap_mail_compose() leaks envelope on malformed bodies).
+    (cmb)
 
 - MySQLnd:
   . Fixed bug #80115 (mysqlnd.debug doesn't recognize absolute paths with
index 0cf350e907b49f84ebae57323b0d1f588a28eb1c..63b5464808a12de3eab45ca24344f3180b45451e 100644 (file)
@@ -3622,7 +3622,8 @@ PHP_FUNCTION(imap_mail_compose)
 
                        if (Z_TYPE_P(data) != IS_ARRAY) {
                                php_error_docref(NULL, E_WARNING, "body parameter must be a non-empty array");
-                               RETURN_FALSE;
+                               RETVAL_FALSE;
+                               goto done;
                        }
                        SEPARATE_ARRAY(data);
 
@@ -3824,7 +3825,8 @@ PHP_FUNCTION(imap_mail_compose)
 
        if (first) {
                php_error_docref(NULL, E_WARNING, "body parameter must be a non-empty array");
-               RETURN_FALSE;
+               RETVAL_FALSE;
+               goto done;
        }
 
        if (bod && bod->type == TYPEMULTIPART && (!bod->nested.part || !bod->nested.part->next)) {
diff --git a/ext/imap/tests/bug80223.phpt b/ext/imap/tests/bug80223.phpt
new file mode 100644 (file)
index 0000000..4acfb8d
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #80223 (imap_mail_compose() leaks envelope on malformed bodies)
+--SKIPIF--
+<?php
+if (!extension_loaded('imap')) die('skip imap extension not available');
+?>
+--FILE--
+<?php
+imap_mail_compose([], []);
+imap_mail_compose([], [1]);
+?>
+--EXPECTF--
+Warning: imap_mail_compose(): body parameter must be a non-empty array in %s on line %d
+
+Warning: imap_mail_compose(): body parameter must be a non-empty array in %s on line %d