Skip to content

Commit

Permalink
Fix #80213: imap_mail_compose() segfaults on certain $bodies
Browse files Browse the repository at this point in the history
We have to cater to non-associative arrays where the key may be `NULL`;
we just skip these elements.

Closes phpGH-6315.
  • Loading branch information
cmb69 committed Oct 10, 2020
1 parent 07a4185 commit 8bee0fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ PHP NEWS
- Calendar:
. Fixed bug #80185 (jdtounix() fails after 2037). (cmb)

- IMAP:
. Fixed bug #80213 (imap_mail_compose() segfaults on certain $bodies). (cmb)

- MySQLnd:
. Fixed bug #80115 (mysqlnd.debug doesn't recognize absolute paths with
slashes). (cmb)
Expand Down
4 changes: 4 additions & 0 deletions ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,7 @@ PHP_FUNCTION(imap_mail_compose)
if(Z_TYPE_P(pvalue) == IS_ARRAY) {
disp_param = tmp_param = NULL;
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) {
if (key == NULL) continue;
disp_param = mail_newbody_parameter();
disp_param->attribute = cpystr(ZSTR_VAL(key));
convert_to_string_ex(disp_data);
Expand Down Expand Up @@ -3677,6 +3678,7 @@ PHP_FUNCTION(imap_mail_compose)
if (Z_TYPE_P(pvalue) == IS_ARRAY) {
disp_param = tmp_param = NULL;
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) {
if (key == NULL) continue;
disp_param = mail_newbody_parameter();
disp_param->attribute = cpystr(ZSTR_VAL(key));
convert_to_string_ex(disp_data);
Expand Down Expand Up @@ -3745,6 +3747,7 @@ PHP_FUNCTION(imap_mail_compose)
if (Z_TYPE_P(pvalue) == IS_ARRAY) {
disp_param = tmp_param = NULL;
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) {
if (key == NULL) continue;
disp_param = mail_newbody_parameter();
disp_param->attribute = cpystr(ZSTR_VAL(key));
convert_to_string_ex(disp_data);
Expand Down Expand Up @@ -3777,6 +3780,7 @@ PHP_FUNCTION(imap_mail_compose)
if (Z_TYPE_P(pvalue) == IS_ARRAY) {
disp_param = tmp_param = NULL;
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) {
if (key == NULL) continue;
disp_param = mail_newbody_parameter();
disp_param->attribute = cpystr(ZSTR_VAL(key));
convert_to_string_ex(disp_data);
Expand Down
21 changes: 21 additions & 0 deletions ext/imap/tests/bug80213.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #80213 (imap_mail_compose() segfaults on certain $bodies)
--SKIPIF--
<?php
if (!extension_loaded('imap')) die('skip imap extension not available');
?>
--FILE--
<?php
$envelope = [];
$body = [[
'type.parameters' => ['param'],
'disposition' => ['disp'],
], [
'type.parameters' => ['param'],
'disposition' => ['disp'],
]];
imap_mail_compose($envelope, $body);
echo "done\n";
?>
--EXPECT--
done

0 comments on commit 8bee0fb

Please sign in to comment.