Skip to content

Commit 4ef7be2

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #80242: imap_mail_compose() segfaults for multipart with rfc822
2 parents a54f0f7 + 315b95b commit 4ef7be2

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug #64076 (imap_sort() does not return FALSE on failure). (cmb)
77
. Fixed bug #80239 (imap_rfc822_write_address() leaks memory). (cmb)
88
. Fixed minor regression caused by fixing bug #80220. (cmb)
9+
. Fixed bug #80242 (imap_mail_compose() segfaults for multipart with rfc822).
10+
(cmb)
911

1012
- Opcache:
1113
. 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
@@ -3836,15 +3836,19 @@ PHP_FUNCTION(imap_mail_compose)
38363836
bod->disposition.parameter = disp_param;
38373837
}
38383838
}
3839-
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
3840-
convert_to_string_ex(pvalue);
3841-
bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
3842-
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue) + 1);
3843-
bod->contents.text.size = Z_STRLEN_P(pvalue);
3839+
if (bod->type == TYPEMESSAGE && bod->subtype && !strcmp(bod->subtype, "RFC822")) {
3840+
bod->nested.msg = mail_newmsg();
38443841
} else {
3845-
bod->contents.text.data = fs_get(1);
3846-
memcpy(bod->contents.text.data, "", 1);
3847-
bod->contents.text.size = 0;
3842+
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
3843+
convert_to_string_ex(pvalue);
3844+
bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
3845+
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue) + 1);
3846+
bod->contents.text.size = Z_STRLEN_P(pvalue);
3847+
} else {
3848+
bod->contents.text.data = fs_get(1);
3849+
memcpy(bod->contents.text.data, "", 1);
3850+
bod->contents.text.size = 0;
3851+
}
38483852
}
38493853
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "lines", sizeof("lines") - 1)) != NULL) {
38503854
bod->size.lines = zval_get_long(pvalue);
@@ -3945,7 +3949,7 @@ PHP_FUNCTION(imap_mail_compose)
39453949

39463950
bod=&part->body;
39473951

3948-
spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data, CRLF);
3952+
spprintf(&tempstring, 0, "%s%s%s", mystring, bod->contents.text.data ? (char *) bod->contents.text.data : "", CRLF);
39493953
efree(mystring);
39503954
mystring=tempstring;
39513955
} while ((part = part->next)); /* until done */

ext/imap/tests/bug80242.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #80242 (imap_mail_compose() segfaults for multipart with rfc822)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('imap')) die('skip imap extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$bodies = [[
10+
'type' => TYPEMULTIPART,
11+
], [
12+
'type' => TYPETEXT,
13+
'contents.data' => 'some text',
14+
], [
15+
'type' => TYPEMESSAGE,
16+
'subtype' => 'RFC822',
17+
]];
18+
imap_mail_compose([], $bodies);
19+
echo "done\n";
20+
?>
21+
--EXPECT--
22+
done

0 commit comments

Comments
 (0)