diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-10-20 13:34:27 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-10-20 13:35:06 +0200 |
commit | 9cfd650697148e7a87a96f34e268b3f24e3df965 (patch) | |
tree | 5eae4bec2982e518a50379e8c690ebf63f48e00d | |
parent | d134c0ac05b6f8969463ff1cf5dd7b6332bf5ab4 (diff) | |
parent | 7f3bdda29bf7123f1f2841c5483e30b5b22981ce (diff) | |
download | php-git-9cfd650697148e7a87a96f34e268b3f24e3df965.tar.gz |
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
Properly fix #80220
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/imap/php_imap.c | 22 | ||||
-rw-r--r-- | ext/imap/tests/bug80220.phpt | 34 |
3 files changed, 48 insertions, 9 deletions
@@ -5,6 +5,7 @@ PHP NEWS - IMAP: . Fixed bug #64076 (imap_sort() does not return FALSE on failure). (cmb) . Fixed bug #80239 (imap_rfc822_write_address() leaks memory). (cmb) + . Fixed minor regression caused by fixing bug #80220. (cmb) - Opcache: . Fixed bug #79643 (PHP with Opcache crashes when a file with specific name diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index f19bc4621c..4c80ace80b 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -3724,15 +3724,19 @@ PHP_FUNCTION(imap_mail_compose) bod->disposition.parameter = disp_param; } } - if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) { - convert_to_string_ex(pvalue); - bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1); - memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); - bod->contents.text.size = Z_STRLEN_P(pvalue); + if (bod->type == TYPEMESSAGE && bod->subtype && !strcmp(bod->subtype, "RFC822")) { + bod->nested.msg = mail_newmsg(); } else { - bod->contents.text.data = fs_get(1); - memcpy(bod->contents.text.data, "", 1); - bod->contents.text.size = 0; + if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) { + convert_to_string_ex(pvalue); + bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1); + memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); + bod->contents.text.size = Z_STRLEN_P(pvalue); + } else { + bod->contents.text.data = fs_get(1); + memcpy(bod->contents.text.data, "", 1); + bod->contents.text.size = 0; + } } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "lines", sizeof("lines") - 1)) != NULL) { bod->size.lines = zval_get_long(pvalue); @@ -3951,7 +3955,7 @@ PHP_FUNCTION(imap_mail_compose) efree(mystring); mystring=tempstring; } else if (bod) { - spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data, CRLF); + spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data ? bod->contents.text.data : "", CRLF); efree(mystring); mystring=tempstring; } else { diff --git a/ext/imap/tests/bug80220.phpt b/ext/imap/tests/bug80220.phpt new file mode 100644 index 0000000000..0d3e3eda9b --- /dev/null +++ b/ext/imap/tests/bug80220.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #80220 (imap_mail_compose() may leak memory) - message/rfc822 regression +--SKIPIF-- +<?php +if (!extension_loaded('imap')) die('skip imap extension not available'); +?> +--FILE-- +<?php +$bodies = [[ + 'type' => TYPEMESSAGE, + 'subtype' => 'RFC822', +], [ + 'contents.data' => 'asd', +]]; +var_dump(imap_mail_compose([], $bodies)); + +$bodies = [[ + 'type' => TYPEMESSAGE, +], [ + 'contents.data' => 'asd', +]]; +var_dump(imap_mail_compose([], $bodies)); +?> +--EXPECT-- +string(53) "MIME-Version: 1.0 +Content-Type: MESSAGE/RFC822 + + +" +string(53) "MIME-Version: 1.0 +Content-Type: MESSAGE/RFC822 + + +" |