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