@@ -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 );
0 commit comments