From f697d1a82fa8a2688dbba8bfcf06c6e50f9396aa Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 12 Oct 2020 13:26:38 +0200 Subject: [PATCH] Fix #80223: imap_mail_compose() leaks envelope on malformed bodies We have to clean up even on failure. --- ext/imap/php_imap.c | 6 ++++-- ext/imap/tests/bug80223.phpt | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 ext/imap/tests/bug80223.phpt diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 7901777f818bf..ab4cc01bb6b6b 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -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 index 0000000000000..4acfb8d02364e --- /dev/null +++ b/ext/imap/tests/bug80223.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #80223 (imap_mail_compose() leaks envelope on malformed bodies) +--SKIPIF-- + +--FILE-- + +--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