@@ -3728,6 +3728,7 @@ PHP_FUNCTION(mb_convert_variables)
3728
3728
const mbfl_encoding * * elist ;
3729
3729
char * to_enc ;
3730
3730
void * ptmp ;
3731
+ int recursion_error = 0 ;
3731
3732
3732
3733
if (zend_parse_parameters (ZEND_NUM_ARGS (), "sz+" , & to_enc , & to_enc_len , & zfrom_enc , & args , & argc ) == FAILURE ) {
3733
3734
return ;
@@ -3792,6 +3793,11 @@ PHP_FUNCTION(mb_convert_variables)
3792
3793
target_hash = HASH_OF (var );
3793
3794
if (target_hash != NULL ) {
3794
3795
while ((hash_entry = zend_hash_get_current_data (target_hash )) != NULL ) {
3796
+ if (++ target_hash -> u .v .nApplyCount > 1 ) {
3797
+ -- target_hash -> u .v .nApplyCount ;
3798
+ recursion_error = 1 ;
3799
+ goto detect_end ;
3800
+ }
3795
3801
zend_hash_move_forward (target_hash );
3796
3802
if (Z_TYPE_P (hash_entry ) == IS_INDIRECT ) {
3797
3803
hash_entry = Z_INDIRECT_P (hash_entry );
@@ -3832,6 +3838,19 @@ PHP_FUNCTION(mb_convert_variables)
3832
3838
from_encoding = mbfl_encoding_detector_judge2 (identd );
3833
3839
mbfl_encoding_detector_delete (identd );
3834
3840
}
3841
+ if (recursion_error ) {
3842
+ while (stack_level -- && (var = & stack [stack_level ])) {
3843
+ if (HASH_OF (var )-> u .v .nApplyCount > 1 ) {
3844
+ HASH_OF (var )-> u .v .nApplyCount -- ;
3845
+ }
3846
+ }
3847
+ efree (stack );
3848
+ if (elist != NULL ) {
3849
+ efree ((void * )elist );
3850
+ }
3851
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Cannot handle recursive references" );
3852
+ RETURN_FALSE ;
3853
+ }
3835
3854
efree (stack );
3836
3855
3837
3856
if (!from_encoding ) {
@@ -3886,6 +3905,11 @@ PHP_FUNCTION(mb_convert_variables)
3886
3905
hash_entry = hash_entry_ptr ;
3887
3906
ZVAL_DEREF (hash_entry );
3888
3907
if (Z_TYPE_P (hash_entry ) == IS_ARRAY || Z_TYPE_P (hash_entry ) == IS_OBJECT ) {
3908
+ if (++ (HASH_OF (hash_entry )-> u .v .nApplyCount ) > 1 ) {
3909
+ -- (HASH_OF (hash_entry )-> u .v .nApplyCount );
3910
+ recursion_error = 1 ;
3911
+ goto conv_end ;
3912
+ }
3889
3913
if (stack_level >= stack_max ) {
3890
3914
stack_max += PHP_MBSTR_STACK_BLOCK_SIZE ;
3891
3915
ptmp = erealloc (stack , sizeof (zval ) * stack_max );
@@ -3925,10 +3949,22 @@ PHP_FUNCTION(mb_convert_variables)
3925
3949
}
3926
3950
}
3927
3951
}
3928
- efree (stack );
3929
3952
3953
+ conv_end :
3930
3954
MBSTRG (illegalchars ) += mbfl_buffer_illegalchars (convd );
3931
3955
mbfl_buffer_converter_delete (convd );
3956
+
3957
+ if (recursion_error ) {
3958
+ while (stack_level -- && (var = & stack [stack_level ])) {
3959
+ if (HASH_OF (var )-> u .v .nApplyCount > 1 ) {
3960
+ HASH_OF (var )-> u .v .nApplyCount -- ;
3961
+ }
3962
+ }
3963
+ efree (stack );
3964
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "Cannot handle recursive references" );
3965
+ RETURN_FALSE ;
3966
+ }
3967
+ efree (stack );
3932
3968
}
3933
3969
3934
3970
if (from_encoding ) {
0 commit comments