Skip to content

Commit 216d6a0

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #80216: imap_mail_compose() does not validate types/encodings
2 parents 4a469c7 + 73e43b6 commit 216d6a0

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
@@ -19,6 +19,8 @@ PHP NEWS
1919
. Fixed bug #80220 (imap_mail_compose() may leak memory). (cmb)
2020
. Fixed bug #80223 (imap_mail_compose() leaks envelope on malformed bodies).
2121
(cmb)
22+
. Fixed bug #80216 (imap_mail_compose() does not validate types/encodings).
23+
(cmb)
2224

2325
- MySQLnd:
2426
. Fixed bug #80115 (mysqlnd.debug doesn't recognize absolute paths with

ext/imap/php_imap.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,10 +3643,16 @@ PHP_FUNCTION(imap_mail_compose)
36433643
topbod = bod;
36443644

36453645
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "type", sizeof("type") - 1)) != NULL) {
3646-
bod->type = (short) zval_get_long(pvalue);
3646+
zend_long type = zval_get_long(pvalue);
3647+
if (type >= 0 && type <= TYPEMAX && body_types[type] != NULL) {
3648+
bod->type = (short) type;
3649+
}
36473650
}
36483651
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "encoding", sizeof("encoding") - 1)) != NULL) {
3649-
bod->encoding = (short) zval_get_long(pvalue);
3652+
zend_long encoding = zval_get_long(pvalue);
3653+
if (encoding >= 0 && encoding <= ENCMAX && body_encodings[encoding] != NULL) {
3654+
bod->encoding = (short) encoding;
3655+
}
36503656
}
36513657
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "charset", sizeof("charset") - 1)) != NULL) {
36523658
convert_to_string_ex(pvalue);
@@ -3728,10 +3734,13 @@ PHP_FUNCTION(imap_mail_compose)
37283734
bod->md5 = cpystr(Z_STRVAL_P(pvalue));
37293735
}
37303736
} else if (Z_TYPE_P(data) == IS_ARRAY && topbod->type == TYPEMULTIPART) {
3731-
short type = -1;
3737+
short type = 0;
37323738
SEPARATE_ARRAY(data);
37333739
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "type", sizeof("type") - 1)) != NULL) {
3734-
type = (short) zval_get_long(pvalue);
3740+
zend_long tmp_type = zval_get_long(pvalue);
3741+
if (tmp_type >= 0 && tmp_type <= TYPEMAX && tmp_type != TYPEMULTIPART && body_types[tmp_type] != NULL) {
3742+
type = (short) tmp_type;
3743+
}
37353744
}
37363745

37373746
if (!toppart) {
@@ -3744,13 +3753,13 @@ PHP_FUNCTION(imap_mail_compose)
37443753
}
37453754

37463755
bod = &mypart->body;
3747-
3748-
if (type != TYPEMULTIPART) {
3749-
bod->type = type;
3750-
}
3756+
bod->type = type;
37513757

37523758
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "encoding", sizeof("encoding") - 1)) != NULL) {
3753-
bod->encoding = (short) zval_get_long(pvalue);
3759+
zend_long encoding = zval_get_long(pvalue);
3760+
if (encoding >= 0 && encoding <= ENCMAX && body_encodings[encoding] != NULL) {
3761+
bod->encoding = (short) encoding;
3762+
}
37543763
}
37553764
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "charset", sizeof("charset") - 1)) != NULL) {
37563765
convert_to_string_ex(pvalue);

ext/imap/tests/bug80216.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #80216 (imap_mail_compose() does not validate types/encodings)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('imap')) die('skip imap extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
imap_mail_compose([], [['type' => TYPEMULTIPART], []]);
10+
imap_mail_compose([], [['type' => 12]]);
11+
imap_mail_compose([], [['type' => TYPEMULTIPART], ['type' => 12]]);
12+
imap_mail_compose([], [['encoding' => 8]]);
13+
imap_mail_compose([], [['type' => TYPEMULTIPART], ['encoding' => 8]]);
14+
echo "done\n";
15+
?>
16+
--EXPECT--
17+
done

0 commit comments

Comments
 (0)