@@ -3862,6 +3862,7 @@ PHP_FUNCTION(mb_convert_variables)
3862
3862
const mbfl_encoding * * elist ;
3863
3863
char * to_enc ;
3864
3864
void * ptmp ;
3865
+ int recursion_error = 0 ;
3865
3866
3866
3867
if (zend_parse_parameters (ZEND_NUM_ARGS (), "sz+" , & to_enc , & to_enc_len , & zfrom_enc , & args , & argc ) == FAILURE ) {
3867
3868
return ;
@@ -3926,6 +3927,11 @@ PHP_FUNCTION(mb_convert_variables)
3926
3927
target_hash = HASH_OF (var );
3927
3928
if (target_hash != NULL ) {
3928
3929
while ((hash_entry = zend_hash_get_current_data (target_hash )) != NULL ) {
3930
+ if (++ target_hash -> u .v .nApplyCount > 1 ) {
3931
+ -- target_hash -> u .v .nApplyCount ;
3932
+ recursion_error = 1 ;
3933
+ goto detect_end ;
3934
+ }
3929
3935
zend_hash_move_forward (target_hash );
3930
3936
if (Z_TYPE_P (hash_entry ) == IS_INDIRECT ) {
3931
3937
hash_entry = Z_INDIRECT_P (hash_entry );
@@ -3966,6 +3972,19 @@ PHP_FUNCTION(mb_convert_variables)
3966
3972
from_encoding = mbfl_encoding_detector_judge2 (identd );
3967
3973
mbfl_encoding_detector_delete (identd );
3968
3974
}
3975
+ if (recursion_error ) {
3976
+ while (stack_level -- && (var = & stack [stack_level ])) {
3977
+ if (HASH_OF (var )-> u .v .nApplyCount > 1 ) {
3978
+ HASH_OF (var )-> u .v .nApplyCount -- ;
3979
+ }
3980
+ }
3981
+ efree (stack );
3982
+ if (elist != NULL ) {
3983
+ efree ((void * )elist );
3984
+ }
3985
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Cannot handle recursive references" );
3986
+ RETURN_FALSE ;
3987
+ }
3969
3988
efree (stack );
3970
3989
3971
3990
if (!from_encoding ) {
@@ -4020,6 +4039,11 @@ PHP_FUNCTION(mb_convert_variables)
4020
4039
hash_entry = hash_entry_ptr ;
4021
4040
ZVAL_DEREF (hash_entry );
4022
4041
if (Z_TYPE_P (hash_entry ) == IS_ARRAY || Z_TYPE_P (hash_entry ) == IS_OBJECT ) {
4042
+ if (++ (HASH_OF (hash_entry )-> u .v .nApplyCount ) > 1 ) {
4043
+ -- (HASH_OF (hash_entry )-> u .v .nApplyCount );
4044
+ recursion_error = 1 ;
4045
+ goto conv_end ;
4046
+ }
4023
4047
if (stack_level >= stack_max ) {
4024
4048
stack_max += PHP_MBSTR_STACK_BLOCK_SIZE ;
4025
4049
ptmp = erealloc (stack , sizeof (zval ) * stack_max );
@@ -4059,10 +4083,22 @@ PHP_FUNCTION(mb_convert_variables)
4059
4083
}
4060
4084
}
4061
4085
}
4062
- efree (stack );
4063
4086
4087
+ conv_end :
4064
4088
MBSTRG (illegalchars ) += mbfl_buffer_illegalchars (convd );
4065
4089
mbfl_buffer_converter_delete (convd );
4090
+
4091
+ if (recursion_error ) {
4092
+ while (stack_level -- && (var = & stack [stack_level ])) {
4093
+ if (HASH_OF (var )-> u .v .nApplyCount > 1 ) {
4094
+ HASH_OF (var )-> u .v .nApplyCount -- ;
4095
+ }
4096
+ }
4097
+ efree (stack );
4098
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Cannot handle recursive references" );
4099
+ RETURN_FALSE ;
4100
+ }
4101
+ efree (stack );
4066
4102
}
4067
4103
4068
4104
if (from_encoding ) {
0 commit comments