Skip to content

Commit 486c49d

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Properly fix #80220
2 parents cf04707 + 9cfd650 commit 486c49d

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
@@ -8,6 +8,7 @@ PHP NEWS
88

99
- IMAP:
1010
. Fixed bug #80239 (imap_rfc822_write_address() leaks memory). (cmb)
11+
. Fixed minor regression caused by fixing bug #80220. (cmb)
1112

1213
- Opcache:
1314
. Fixed bug #80255 (Opcache bug (bad condition result) in 8.0.0rc1). (Nikita)

ext/imap/php_imap.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,15 +3263,19 @@ PHP_FUNCTION(imap_mail_compose)
32633263
bod->disposition.parameter = disp_param;
32643264
}
32653265
}
3266-
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
3267-
convert_to_string_ex(pvalue);
3268-
bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
3269-
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1);
3270-
bod->contents.text.size = Z_STRLEN_P(pvalue);
3266+
if (bod->type == TYPEMESSAGE && bod->subtype && !strcmp(bod->subtype, "RFC822")) {
3267+
bod->nested.msg = mail_newmsg();
32713268
} else {
3272-
bod->contents.text.data = fs_get(1);
3273-
memcpy(bod->contents.text.data, "", 1);
3274-
bod->contents.text.size = 0;
3269+
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
3270+
convert_to_string_ex(pvalue);
3271+
bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
3272+
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1);
3273+
bod->contents.text.size = Z_STRLEN_P(pvalue);
3274+
} else {
3275+
bod->contents.text.data = fs_get(1);
3276+
memcpy(bod->contents.text.data, "", 1);
3277+
bod->contents.text.size = 0;
3278+
}
32753279
}
32763280
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "lines", sizeof("lines") - 1)) != NULL) {
32773281
bod->size.lines = zval_get_long(pvalue);
@@ -3491,7 +3495,7 @@ PHP_FUNCTION(imap_mail_compose)
34913495
efree(mystring);
34923496
mystring=tempstring;
34933497
} else if (bod) {
3494-
spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data, CRLF);
3498+
spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data ? bod->contents.text.data : "", CRLF);
34953499
efree(mystring);
34963500
mystring=tempstring;
34973501
} 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)