@@ -3631,10 +3631,16 @@ PHP_FUNCTION(imap_mail_compose)
36313631 topbod = bod ;
36323632
36333633 if ((pvalue = zend_hash_str_find (Z_ARRVAL_P (data ), "type" , sizeof ("type" ) - 1 )) != NULL ) {
3634- bod -> type = (short ) zval_get_long (pvalue );
3634+ zend_long type = zval_get_long (pvalue );
3635+ if (type >= 0 && type <= TYPEMAX && body_types [type ] != NULL ) {
3636+ bod -> type = (short ) type ;
3637+ }
36353638 }
36363639 if ((pvalue = zend_hash_str_find (Z_ARRVAL_P (data ), "encoding" , sizeof ("encoding" ) - 1 )) != NULL ) {
3637- bod -> encoding = (short ) zval_get_long (pvalue );
3640+ zend_long encoding = zval_get_long (pvalue );
3641+ if (encoding >= 0 && encoding <= ENCMAX && body_encodings [encoding ] != NULL ) {
3642+ bod -> encoding = (short ) encoding ;
3643+ }
36383644 }
36393645 if ((pvalue = zend_hash_str_find (Z_ARRVAL_P (data ), "charset" , sizeof ("charset" ) - 1 )) != NULL ) {
36403646 convert_to_string_ex (pvalue );
@@ -3716,10 +3722,13 @@ PHP_FUNCTION(imap_mail_compose)
37163722 bod -> md5 = cpystr (Z_STRVAL_P (pvalue ));
37173723 }
37183724 } else if (Z_TYPE_P (data ) == IS_ARRAY && topbod -> type == TYPEMULTIPART ) {
3719- short type = -1 ;
3725+ short type = 0 ;
37203726 SEPARATE_ARRAY (data );
37213727 if ((pvalue = zend_hash_str_find (Z_ARRVAL_P (data ), "type" , sizeof ("type" ) - 1 )) != NULL ) {
3722- type = (short ) zval_get_long (pvalue );
3728+ zend_long tmp_type = zval_get_long (pvalue );
3729+ if (tmp_type >= 0 && tmp_type <= TYPEMAX && tmp_type != TYPEMULTIPART && body_types [tmp_type ] != NULL ) {
3730+ type = (short ) tmp_type ;
3731+ }
37233732 }
37243733
37253734 if (!toppart ) {
@@ -3732,13 +3741,13 @@ PHP_FUNCTION(imap_mail_compose)
37323741 }
37333742
37343743 bod = & mypart -> body ;
3735-
3736- if (type != TYPEMULTIPART ) {
3737- bod -> type = type ;
3738- }
3744+ bod -> type = type ;
37393745
37403746 if ((pvalue = zend_hash_str_find (Z_ARRVAL_P (data ), "encoding" , sizeof ("encoding" ) - 1 )) != NULL ) {
3741- bod -> encoding = (short ) zval_get_long (pvalue );
3747+ zend_long encoding = zval_get_long (pvalue );
3748+ if (encoding >= 0 && encoding <= ENCMAX && body_encodings [encoding ] != NULL ) {
3749+ bod -> encoding = (short ) encoding ;
3750+ }
37423751 }
37433752 if ((pvalue = zend_hash_str_find (Z_ARRVAL_P (data ), "charset" , sizeof ("charset" ) - 1 )) != NULL ) {
37443753 convert_to_string_ex (pvalue );
0 commit comments