@@ -364,6 +364,14 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
364
364
const lit_utf8_byte_t * str_p , /**< input string pointer */
365
365
const lit_utf8_byte_t * * out_str_p ) /**< [out] matching substring iterator */
366
366
{
367
+ #ifdef REGEXP_RECURSION_LIMIT
368
+ if (re_ctx_p -> recursion_depth >= REGEXP_RECURSION_LIMIT )
369
+ {
370
+ ecma_value_t ret_value = ecma_raise_range_error ("RegExp executor recursion limit is exceeded." );
371
+ return ret_value ;
372
+ }
373
+ ++ re_ctx_p -> recursion_depth ;
374
+ #endif /* REGEXP_RECURSION_LIMIT */
367
375
const lit_utf8_byte_t * str_curr_p = str_p ;
368
376
369
377
while (true)
@@ -535,6 +543,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
535
543
if (!sub_str_p )
536
544
{
537
545
match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
546
+ #ifdef REGEXP_RECURSION_LIMIT
547
+ -- re_ctx_p -> recursion_depth ;
548
+ #endif /* REGEXP_RECURSION_LIMIT */
538
549
if (ECMA_IS_VALUE_ERROR (match_value ))
539
550
{
540
551
break ;
@@ -553,6 +564,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
553
564
{
554
565
JERRY_TRACE_MSG ("match\n" );
555
566
match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
567
+ #ifdef REGEXP_RECURSION_LIMIT
568
+ -- re_ctx_p -> recursion_depth ;
569
+ #endif /* REGEXP_RECURSION_LIMIT */
556
570
}
557
571
else
558
572
{
@@ -685,6 +699,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
685
699
uint32_t offset = re_get_value (& bc_p );
686
700
const lit_utf8_byte_t * sub_str_p = NULL ;
687
701
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
702
+ #ifdef REGEXP_RECURSION_LIMIT
703
+ -- re_ctx_p -> recursion_depth ;
704
+ #endif /* REGEXP_RECURSION_LIMIT */
688
705
689
706
if (ecma_is_value_true (match_value ))
690
707
{
@@ -770,6 +787,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
770
787
771
788
/* Try to match after the close paren if zero is allowed */
772
789
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
790
+ #ifdef REGEXP_RECURSION_LIMIT
791
+ -- re_ctx_p -> recursion_depth ;
792
+ #endif /* REGEXP_RECURSION_LIMIT */
773
793
774
794
if (ecma_is_value_true (match_value ))
775
795
{
@@ -828,6 +848,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
828
848
{
829
849
offset = re_get_value (& bc_p );
830
850
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
851
+ #ifdef REGEXP_RECURSION_LIMIT
852
+ -- re_ctx_p -> recursion_depth ;
853
+ #endif /* REGEXP_RECURSION_LIMIT */
831
854
832
855
if (ecma_is_value_true (match_value ))
833
856
{
@@ -852,6 +875,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
852
875
{
853
876
JERRY_ASSERT (end_bc_p );
854
877
ecma_value_t match_value = re_match_regexp (re_ctx_p , end_bc_p , str_curr_p , & sub_str_p );
878
+ #ifdef REGEXP_RECURSION_LIMIT
879
+ -- re_ctx_p -> recursion_depth ;
880
+ #endif /* REGEXP_RECURSION_LIMIT */
855
881
856
882
if (ecma_is_value_true (match_value ))
857
883
{
@@ -906,6 +932,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
906
932
907
933
const lit_utf8_byte_t * sub_str_p = NULL ;
908
934
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
935
+ #ifdef REGEXP_RECURSION_LIMIT
936
+ -- re_ctx_p -> recursion_depth ;
937
+ #endif /* REGEXP_RECURSION_LIMIT */
909
938
910
939
if (ecma_is_value_true (match_value ))
911
940
{
@@ -975,6 +1004,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
975
1004
old_start_p = re_ctx_p -> saved_p [start_idx ];
976
1005
re_ctx_p -> saved_p [start_idx ] = str_curr_p ;
977
1006
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
1007
+ #ifdef REGEXP_RECURSION_LIMIT
1008
+ -- re_ctx_p -> recursion_depth ;
1009
+ #endif /* REGEXP_RECURSION_LIMIT */
978
1010
979
1011
if (ecma_is_value_true (match_value ))
980
1012
{
@@ -999,6 +1031,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
999
1031
re_ctx_p -> saved_p [start_idx ] = str_curr_p ;
1000
1032
1001
1033
match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
1034
+ #ifdef REGEXP_RECURSION_LIMIT
1035
+ -- re_ctx_p -> recursion_depth ;
1036
+ #endif /* REGEXP_RECURSION_LIMIT */
1002
1037
1003
1038
if (ecma_is_value_true (match_value ))
1004
1039
{
@@ -1020,6 +1055,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1020
1055
{
1021
1056
/* Try to match the rest of the bytecode. */
1022
1057
ecma_value_t match_value = re_match_regexp (re_ctx_p , old_bc_p , str_curr_p , & sub_str_p );
1058
+ #ifdef REGEXP_RECURSION_LIMIT
1059
+ -- re_ctx_p -> recursion_depth ;
1060
+ #endif /* REGEXP_RECURSION_LIMIT */
1023
1061
1024
1062
if (ecma_is_value_true (match_value ))
1025
1063
{
@@ -1055,6 +1093,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1055
1093
if (num_of_iter >= min )
1056
1094
{
1057
1095
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p + offset , str_curr_p , & sub_str_p );
1096
+ #ifdef REGEXP_RECURSION_LIMIT
1097
+ -- re_ctx_p -> recursion_depth ;
1098
+ #endif /* REGEXP_RECURSION_LIMIT */
1058
1099
1059
1100
if (ecma_is_value_true (match_value ))
1060
1101
{
@@ -1068,6 +1109,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1068
1109
}
1069
1110
1070
1111
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
1112
+ #ifdef REGEXP_RECURSION_LIMIT
1113
+ -- re_ctx_p -> recursion_depth ;
1114
+ #endif /* REGEXP_RECURSION_LIMIT */
1071
1115
1072
1116
if (!ecma_is_value_true (match_value ))
1073
1117
{
@@ -1103,6 +1147,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1103
1147
while (num_of_iter < max )
1104
1148
{
1105
1149
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p , str_curr_p , & sub_str_p );
1150
+ #ifdef REGEXP_RECURSION_LIMIT
1151
+ -- re_ctx_p -> recursion_depth ;
1152
+ #endif /* REGEXP_RECURSION_LIMIT */
1106
1153
1107
1154
if (!ecma_is_value_true (match_value ))
1108
1155
{
@@ -1121,6 +1168,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1121
1168
while (num_of_iter >= min )
1122
1169
{
1123
1170
ecma_value_t match_value = re_match_regexp (re_ctx_p , bc_p + offset , str_curr_p , & sub_str_p );
1171
+ #ifdef REGEXP_RECURSION_LIMIT
1172
+ -- re_ctx_p -> recursion_depth ;
1173
+ #endif /* REGEXP_RECURSION_LIMIT */
1124
1174
1125
1175
if (ecma_is_value_true (match_value ))
1126
1176
{
@@ -1232,6 +1282,9 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
1232
1282
re_ctx .input_start_p = input_curr_p ;
1233
1283
const lit_utf8_byte_t * input_end_p = re_ctx .input_start_p + input_buffer_size ;
1234
1284
re_ctx .input_end_p = input_end_p ;
1285
+ #ifdef REGEXP_RECURSION_LIMIT
1286
+ re_ctx .recursion_depth = 0 ;
1287
+ #endif /* REGEXP_RECURSION_LIMIT */
1235
1288
1236
1289
/* 1. Read bytecode header and init regexp matcher context. */
1237
1290
re_ctx .flags = bc_p -> header .status_flags ;
0 commit comments