Skip to content

Commit 9cfd650

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Properly fix #80220
2 parents d134c0a + 7f3bdda commit 9cfd650

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- IMAP:
66
. Fixed bug #64076 (imap_sort() does not return FALSE on failure). (cmb)
77
. Fixed bug #80239 (imap_rfc822_write_address() leaks memory). (cmb)
8+
. Fixed minor regression caused by fixing bug #80220. (cmb)
89

910
- Opcache:
1011
. Fixed bug #79643 (PHP with Opcache crashes when a file with specific name

ext/imap/php_imap.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,15 +3724,19 @@ PHP_FUNCTION(imap_mail_compose)
37243724
bod->disposition.parameter = disp_param;
37253725
}
37263726
}
3727-
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
3728-
convert_to_string_ex(pvalue);
3729-
bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
3730-
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1);
3731-
bod->contents.text.size = Z_STRLEN_P(pvalue);
3727+
if (bod->type == TYPEMESSAGE && bod->subtype && !strcmp(bod->subtype, "RFC822")) {
3728+
bod->nested.msg = mail_newmsg();
37323729
} else {
3733-
bod->contents.text.data = fs_get(1);
3734-
memcpy(bod->contents.text.data, "", 1);
3735-
bod->contents.text.size = 0;
3730+
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
3731+
convert_to_string_ex(pvalue);
3732+
bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
3733+
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1);
3734+
bod->contents.text.size = Z_STRLEN_P(pvalue);
3735+
} else {
3736+
bod->contents.text.data = fs_get(1);
3737+
memcpy(bod->contents.text.data, "", 1);
3738+
bod->contents.text.size = 0;
3739+
}
37363740
}
37373741
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "lines", sizeof("lines") - 1)) != NULL) {
37383742
bod->size.lines = zval_get_long(pvalue);
@@ -3951,7 +3955,7 @@ PHP_FUNCTION(imap_mail_compose)
39513955
efree(mystring);
39523956
mystring=tempstring;
39533957
} else if (bod) {
3954-
spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data, CRLF);
3958+
spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data ? bod->contents.text.data : "", CRLF);
39553959
efree(mystring);
39563960
mystring=tempstring;
39573961
} else {

ext/imap/tests/bug80220.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #80220 (imap_mail_compose() may leak memory) - message/rfc822 regression
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('imap')) die('skip imap extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$bodies = [[
10+
'type' => TYPEMESSAGE,
11+
'subtype' => 'RFC822',
12+
], [
13+
'contents.data' => 'asd',
14+
]];
15+
var_dump(imap_mail_compose([], $bodies));
16+
17+
$bodies = [[
18+
'type' => TYPEMESSAGE,
19+
], [
20+
'contents.data' => 'asd',
21+
]];
22+
var_dump(imap_mail_compose([], $bodies));
23+
?>
24+
--EXPECT--
25+
string(53) "MIME-Version: 1.0
26+
Content-Type: MESSAGE/RFC822
27+
28+
29+
"
30+
string(53) "MIME-Version: 1.0
31+
Content-Type: MESSAGE/RFC822
32+
33+
34+
"

0 commit comments

Comments
 (0)