@@ -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)
@@ -376,12 +384,18 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
376
384
{
377
385
JERRY_TRACE_MSG ("Execute RE_OP_MATCH: match\n" );
378
386
* out_str_p = str_curr_p ;
387
+ #ifdef REGEXP_RECURSION_LIMIT
388
+ -- re_ctx_p -> recursion_depth ;
389
+ #endif /* REGEXP_RECURSION_LIMIT */
379
390
return ECMA_VALUE_TRUE ; /* match */
380
391
}
381
392
case RE_OP_CHAR :
382
393
{
383
394
if (str_curr_p >= re_ctx_p -> input_end_p )
384
395
{
396
+ #ifdef REGEXP_RECURSION_LIMIT
397
+ -- re_ctx_p -> recursion_depth ;
398
+ #endif /* REGEXP_RECURSION_LIMIT */
385
399
return ECMA_VALUE_FALSE ; /* fail */
386
400
}
387
401
@@ -393,6 +407,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
393
407
if (ch1 != ch2 )
394
408
{
395
409
JERRY_TRACE_MSG ("fail\n" );
410
+ #ifdef REGEXP_RECURSION_LIMIT
411
+ -- re_ctx_p -> recursion_depth ;
412
+ #endif /* REGEXP_RECURSION_LIMIT */
396
413
return ECMA_VALUE_FALSE ; /* fail */
397
414
}
398
415
@@ -404,6 +421,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
404
421
{
405
422
if (str_curr_p >= re_ctx_p -> input_end_p )
406
423
{
424
+ #ifdef REGEXP_RECURSION_LIMIT
425
+ -- re_ctx_p -> recursion_depth ;
426
+ #endif /* REGEXP_RECURSION_LIMIT */
407
427
return ECMA_VALUE_FALSE ; /* fail */
408
428
}
409
429
@@ -413,6 +433,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
413
433
if (lit_char_is_line_terminator (ch ))
414
434
{
415
435
JERRY_TRACE_MSG ("fail\n" );
436
+ #ifdef REGEXP_RECURSION_LIMIT
437
+ -- re_ctx_p -> recursion_depth ;
438
+ #endif /* REGEXP_RECURSION_LIMIT */
416
439
return ECMA_VALUE_FALSE ; /* fail */
417
440
}
418
441
@@ -432,6 +455,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
432
455
if (!(re_ctx_p -> flags & RE_FLAG_MULTILINE ))
433
456
{
434
457
JERRY_TRACE_MSG ("fail\n" );
458
+ #ifdef REGEXP_RECURSION_LIMIT
459
+ -- re_ctx_p -> recursion_depth ;
460
+ #endif /* REGEXP_RECURSION_LIMIT */
435
461
return ECMA_VALUE_FALSE ; /* fail */
436
462
}
437
463
@@ -442,6 +468,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
442
468
}
443
469
444
470
JERRY_TRACE_MSG ("fail\n" );
471
+ #ifdef REGEXP_RECURSION_LIMIT
472
+ -- re_ctx_p -> recursion_depth ;
473
+ #endif /* REGEXP_RECURSION_LIMIT */
445
474
return ECMA_VALUE_FALSE ; /* fail */
446
475
}
447
476
case RE_OP_ASSERT_END :
@@ -457,6 +486,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
457
486
if (!(re_ctx_p -> flags & RE_FLAG_MULTILINE ))
458
487
{
459
488
JERRY_TRACE_MSG ("fail\n" );
489
+ #ifdef REGEXP_RECURSION_LIMIT
490
+ -- re_ctx_p -> recursion_depth ;
491
+ #endif /* REGEXP_RECURSION_LIMIT */
460
492
return ECMA_VALUE_FALSE ; /* fail */
461
493
}
462
494
@@ -467,6 +499,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
467
499
}
468
500
469
501
JERRY_TRACE_MSG ("fail\n" );
502
+ #ifdef REGEXP_RECURSION_LIMIT
503
+ -- re_ctx_p -> recursion_depth ;
504
+ #endif /* REGEXP_RECURSION_LIMIT */
470
505
return ECMA_VALUE_FALSE ; /* fail */
471
506
}
472
507
case RE_OP_ASSERT_WORD_BOUNDARY :
@@ -498,6 +533,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
498
533
if (is_wordchar_left == is_wordchar_right )
499
534
{
500
535
JERRY_TRACE_MSG ("fail\n" );
536
+ #ifdef REGEXP_RECURSION_LIMIT
537
+ -- re_ctx_p -> recursion_depth ;
538
+ #endif /* REGEXP_RECURSION_LIMIT */
501
539
return ECMA_VALUE_FALSE ; /* fail */
502
540
}
503
541
}
@@ -509,6 +547,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
509
547
if (is_wordchar_left != is_wordchar_right )
510
548
{
511
549
JERRY_TRACE_MSG ("fail\n" );
550
+ #ifdef REGEXP_RECURSION_LIMIT
551
+ -- re_ctx_p -> recursion_depth ;
552
+ #endif /* REGEXP_RECURSION_LIMIT */
512
553
return ECMA_VALUE_FALSE ; /* fail */
513
554
}
514
555
}
@@ -563,6 +604,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
563
604
564
605
if (!ECMA_IS_VALUE_ERROR (match_value ))
565
606
{
607
+ #ifdef REGEXP_RECURSION_LIMIT
608
+ -- re_ctx_p -> recursion_depth ;
609
+ #endif /* REGEXP_RECURSION_LIMIT */
566
610
if (ecma_is_value_true (match_value ))
567
611
{
568
612
* out_str_p = sub_str_p ;
@@ -588,6 +632,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
588
632
if (str_curr_p >= re_ctx_p -> input_end_p )
589
633
{
590
634
JERRY_TRACE_MSG ("fail\n" );
635
+ #ifdef REGEXP_RECURSION_LIMIT
636
+ -- re_ctx_p -> recursion_depth ;
637
+ #endif /* REGEXP_RECURSION_LIMIT */
591
638
return ECMA_VALUE_FALSE ; /* fail */
592
639
}
593
640
@@ -618,6 +665,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
618
665
if (!is_match )
619
666
{
620
667
JERRY_TRACE_MSG ("fail\n" );
668
+ #ifdef REGEXP_RECURSION_LIMIT
669
+ -- re_ctx_p -> recursion_depth ;
670
+ #endif /* REGEXP_RECURSION_LIMIT */
621
671
return ECMA_VALUE_FALSE ; /* fail */
622
672
}
623
673
}
@@ -627,6 +677,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
627
677
if (is_match )
628
678
{
629
679
JERRY_TRACE_MSG ("fail\n" );
680
+ #ifdef REGEXP_RECURSION_LIMIT
681
+ -- re_ctx_p -> recursion_depth ;
682
+ #endif /* REGEXP_RECURSION_LIMIT */
630
683
return ECMA_VALUE_FALSE ; /* fail */
631
684
}
632
685
}
@@ -657,6 +710,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
657
710
if (str_curr_p >= re_ctx_p -> input_end_p )
658
711
{
659
712
JERRY_TRACE_MSG ("fail\n" );
713
+ #ifdef REGEXP_RECURSION_LIMIT
714
+ -- re_ctx_p -> recursion_depth ;
715
+ #endif /* REGEXP_RECURSION_LIMIT */
660
716
return ECMA_VALUE_FALSE ; /* fail */
661
717
}
662
718
@@ -666,6 +722,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
666
722
if (ch1 != ch2 )
667
723
{
668
724
JERRY_TRACE_MSG ("fail\n" );
725
+ #ifdef REGEXP_RECURSION_LIMIT
726
+ -- re_ctx_p -> recursion_depth ;
727
+ #endif /* REGEXP_RECURSION_LIMIT */
669
728
return ECMA_VALUE_FALSE ; /* fail */
670
729
}
671
730
}
@@ -689,6 +748,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
689
748
if (ecma_is_value_true (match_value ))
690
749
{
691
750
* out_str_p = sub_str_p ;
751
+ #ifdef REGEXP_RECURSION_LIMIT
752
+ -- re_ctx_p -> recursion_depth ;
753
+ #endif /* REGEXP_RECURSION_LIMIT */
692
754
return match_value ; /* match */
693
755
}
694
756
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -703,13 +765,19 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
703
765
bc_p = old_bc_p ;
704
766
705
767
re_ctx_p -> saved_p [RE_GLOBAL_START_IDX ] = old_start_p ;
768
+ #ifdef REGEXP_RECURSION_LIMIT
769
+ -- re_ctx_p -> recursion_depth ;
770
+ #endif /* REGEXP_RECURSION_LIMIT */
706
771
return ECMA_VALUE_FALSE ; /* fail */
707
772
}
708
773
case RE_OP_SAVE_AND_MATCH :
709
774
{
710
775
JERRY_TRACE_MSG ("End of pattern is reached: match\n" );
711
776
re_ctx_p -> saved_p [RE_GLOBAL_END_IDX ] = str_curr_p ;
712
777
* out_str_p = str_curr_p ;
778
+ #ifdef REGEXP_RECURSION_LIMIT
779
+ -- re_ctx_p -> recursion_depth ;
780
+ #endif /* REGEXP_RECURSION_LIMIT */
713
781
return ECMA_VALUE_TRUE ; /* match */
714
782
}
715
783
case RE_OP_ALTERNATIVE :
@@ -774,6 +842,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
774
842
if (ecma_is_value_true (match_value ))
775
843
{
776
844
* out_str_p = sub_str_p ;
845
+ #ifdef REGEXP_RECURSION_LIMIT
846
+ -- re_ctx_p -> recursion_depth ;
847
+ #endif /* REGEXP_RECURSION_LIMIT */
777
848
return match_value ; /* match */
778
849
}
779
850
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -832,6 +903,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
832
903
if (ecma_is_value_true (match_value ))
833
904
{
834
905
* out_str_p = sub_str_p ;
906
+ #ifdef REGEXP_RECURSION_LIMIT
907
+ -- re_ctx_p -> recursion_depth ;
908
+ #endif /* REGEXP_RECURSION_LIMIT */
835
909
return match_value ; /* match */
836
910
}
837
911
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -856,6 +930,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
856
930
if (ecma_is_value_true (match_value ))
857
931
{
858
932
* out_str_p = sub_str_p ;
933
+ #ifdef REGEXP_RECURSION_LIMIT
934
+ -- re_ctx_p -> recursion_depth ;
935
+ #endif /* REGEXP_RECURSION_LIMIT */
859
936
return match_value ; /* match */
860
937
}
861
938
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -865,6 +942,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
865
942
}
866
943
867
944
re_ctx_p -> saved_p [start_idx ] = old_start_p ;
945
+ #ifdef REGEXP_RECURSION_LIMIT
946
+ -- re_ctx_p -> recursion_depth ;
947
+ #endif /* REGEXP_RECURSION_LIMIT */
868
948
return ECMA_VALUE_FALSE ; /* fail */
869
949
}
870
950
case RE_OP_CAPTURE_NON_GREEDY_GROUP_END :
@@ -910,6 +990,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
910
990
if (ecma_is_value_true (match_value ))
911
991
{
912
992
* out_str_p = sub_str_p ;
993
+ #ifdef REGEXP_RECURSION_LIMIT
994
+ -- re_ctx_p -> recursion_depth ;
995
+ #endif /* REGEXP_RECURSION_LIMIT */
913
996
return match_value ; /* match */
914
997
}
915
998
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -958,6 +1041,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
958
1041
if (re_ctx_p -> num_of_iterations_p [iter_idx ] >= min
959
1042
&& str_curr_p == re_ctx_p -> saved_p [start_idx ])
960
1043
{
1044
+ #ifdef REGEXP_RECURSION_LIMIT
1045
+ -- re_ctx_p -> recursion_depth ;
1046
+ #endif /* REGEXP_RECURSION_LIMIT */
961
1047
return ECMA_VALUE_FALSE ; /* fail */
962
1048
}
963
1049
@@ -979,6 +1065,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
979
1065
if (ecma_is_value_true (match_value ))
980
1066
{
981
1067
* out_str_p = sub_str_p ;
1068
+ #ifdef REGEXP_RECURSION_LIMIT
1069
+ -- re_ctx_p -> recursion_depth ;
1070
+ #endif /* REGEXP_RECURSION_LIMIT */
982
1071
return match_value ; /* match */
983
1072
}
984
1073
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -1003,6 +1092,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1003
1092
if (ecma_is_value_true (match_value ))
1004
1093
{
1005
1094
* out_str_p = sub_str_p ;
1095
+ #ifdef REGEXP_RECURSION_LIMIT
1096
+ -- re_ctx_p -> recursion_depth ;
1097
+ #endif /* REGEXP_RECURSION_LIMIT */
1006
1098
return match_value ; /* match */
1007
1099
}
1008
1100
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -1024,6 +1116,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1024
1116
if (ecma_is_value_true (match_value ))
1025
1117
{
1026
1118
* out_str_p = sub_str_p ;
1119
+ #ifdef REGEXP_RECURSION_LIMIT
1120
+ -- re_ctx_p -> recursion_depth ;
1121
+ #endif /* REGEXP_RECURSION_LIMIT */
1027
1122
return match_value ; /* match */
1028
1123
}
1029
1124
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -1035,6 +1130,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1035
1130
/* restore if fails */
1036
1131
re_ctx_p -> saved_p [end_idx ] = old_end_p ;
1037
1132
re_ctx_p -> num_of_iterations_p [iter_idx ]-- ;
1133
+ #ifdef REGEXP_RECURSION_LIMIT
1134
+ -- re_ctx_p -> recursion_depth ;
1135
+ #endif /* REGEXP_RECURSION_LIMIT */
1038
1136
return ECMA_VALUE_FALSE ; /* fail */
1039
1137
}
1040
1138
case RE_OP_NON_GREEDY_ITERATOR :
@@ -1059,6 +1157,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1059
1157
if (ecma_is_value_true (match_value ))
1060
1158
{
1061
1159
* out_str_p = sub_str_p ;
1160
+ #ifdef REGEXP_RECURSION_LIMIT
1161
+ -- re_ctx_p -> recursion_depth ;
1162
+ #endif /* REGEXP_RECURSION_LIMIT */
1062
1163
return match_value ; /* match */
1063
1164
}
1064
1165
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -1082,6 +1183,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1082
1183
str_curr_p = sub_str_p ;
1083
1184
num_of_iter ++ ;
1084
1185
}
1186
+ #ifdef REGEXP_RECURSION_LIMIT
1187
+ -- re_ctx_p -> recursion_depth ;
1188
+ #endif /* REGEXP_RECURSION_LIMIT */
1085
1189
return ECMA_VALUE_FALSE ; /* fail */
1086
1190
}
1087
1191
default :
@@ -1125,6 +1229,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1125
1229
if (ecma_is_value_true (match_value ))
1126
1230
{
1127
1231
* out_str_p = sub_str_p ;
1232
+ #ifdef REGEXP_RECURSION_LIMIT
1233
+ -- re_ctx_p -> recursion_depth ;
1234
+ #endif /* REGEXP_RECURSION_LIMIT */
1128
1235
return match_value ; /* match */
1129
1236
}
1130
1237
else if (ECMA_IS_VALUE_ERROR (match_value ))
@@ -1140,6 +1247,9 @@ re_match_regexp (re_matcher_ctx_t *re_ctx_p, /**< RegExp matcher context */
1140
1247
lit_utf8_read_prev (& str_curr_p );
1141
1248
num_of_iter -- ;
1142
1249
}
1250
+ #ifdef REGEXP_RECURSION_LIMIT
1251
+ -- re_ctx_p -> recursion_depth ;
1252
+ #endif /* REGEXP_RECURSION_LIMIT */
1143
1253
return ECMA_VALUE_FALSE ; /* fail */
1144
1254
}
1145
1255
}
@@ -1232,6 +1342,9 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
1232
1342
re_ctx .input_start_p = input_curr_p ;
1233
1343
const lit_utf8_byte_t * input_end_p = re_ctx .input_start_p + input_buffer_size ;
1234
1344
re_ctx .input_end_p = input_end_p ;
1345
+ #ifdef REGEXP_RECURSION_LIMIT
1346
+ re_ctx .recursion_depth = 0 ;
1347
+ #endif /* REGEXP_RECURSION_LIMIT */
1235
1348
1236
1349
/* 1. Read bytecode header and init regexp matcher context. */
1237
1350
re_ctx .flags = bc_p -> header .status_flags ;
0 commit comments