forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9bbf6f7
committed
Prevent regexp back-refs from sometimes matching when they shouldn't.
The recursion in cdissect() was careless about clearing match datafor capturing parentheses after rejecting a partial match. Thiscould allow a later back-reference to succeed when by rights itshould fail for lack of a defined referent.To fix, think a little more rigorously about what the contractbetween different levels of cdissect's recursion needs to be.With the right spec, we can fix this using fewer rather than moreresets of the match data; the key decision being that a failedsub-match is now explicitly responsible for clearing any matchesit may have set.There are enough other cross-checks and optimizations in the codethat it's not especially easy to exhibit this problem; usually, thematch will fail as-expected. Plus, regexps that are even potentiallyvulnerable are most likely user errors, since there's just not muchpoint in writing a back-ref that doesn't always have a referent.These facts perhaps explain why the issue hasn't been detected,even though it's almost certainly a couple of decades old.Discussion:https://postgr.es/m/151435.1629733387@sss.pgh.pa.us1 parent515e3d8 commit9bbf6f7
File tree
5 files changed
+71
-12
lines changed- src
- backend/regex
- test
- modules/test_regex
- expected
- sql
- regress
- expected
- sql
5 files changed
+71
-12
lines changedLines changed: 36 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
216 | 216 |
| |
217 | 217 |
| |
218 | 218 |
| |
219 |
| - | |
| 219 | + | |
| 220 | + | |
220 | 221 |
| |
221 | 222 |
| |
222 |
| - | |
223 |
| - | |
| 223 | + | |
224 | 224 |
| |
225 | 225 |
| |
226 |
| - | |
| 226 | + | |
227 | 227 |
| |
228 | 228 |
| |
229 | 229 |
| |
| |||
488 | 488 |
| |
489 | 489 |
| |
490 | 490 |
| |
491 |
| - | |
492 | 491 |
| |
493 | 492 |
| |
494 | 493 |
| |
| |||
599 | 598 |
| |
600 | 599 |
| |
601 | 600 |
| |
602 |
| - | |
603 | 601 |
| |
604 | 602 |
| |
605 | 603 |
| |
| |||
647 | 645 |
| |
648 | 646 |
| |
649 | 647 |
| |
| 648 | + | |
| 649 | + | |
650 | 650 |
| |
651 | 651 |
| |
652 | 652 |
| |
| |||
716 | 716 |
| |
717 | 717 |
| |
718 | 718 |
| |
719 |
| - | |
720 |
| - | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
721 | 743 |
| |
722 | 744 |
| |
723 | 745 |
| |
| |||
841 | 863 |
| |
842 | 864 |
| |
843 | 865 |
| |
| 866 | + | |
| 867 | + | |
844 | 868 |
| |
845 | 869 |
| |
846 | 870 |
| |
| |||
863 | 887 |
| |
864 | 888 |
| |
865 | 889 |
| |
866 |
| - | |
867 |
| - | |
868 | 890 |
| |
869 | 891 |
| |
870 | 892 |
| |
| |||
922 | 944 |
| |
923 | 945 |
| |
924 | 946 |
| |
| 947 | + | |
| 948 | + | |
925 | 949 |
| |
926 | 950 |
| |
927 | 951 |
| |
| |||
944 | 968 |
| |
945 | 969 |
| |
946 | 970 |
| |
947 |
| - | |
948 |
| - | |
949 | 971 |
| |
950 | 972 |
| |
951 | 973 |
| |
| |||
1214 | 1236 |
| |
1215 | 1237 |
| |
1216 | 1238 |
| |
| 1239 | + | |
1217 | 1240 |
| |
1218 | 1241 |
| |
1219 | 1242 |
| |
| |||
1426 | 1449 |
| |
1427 | 1450 |
| |
1428 | 1451 |
| |
| 1452 | + | |
1429 | 1453 |
| |
1430 | 1454 |
| |
1431 | 1455 |
| |
|
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2664 | 2664 |
| |
2665 | 2665 |
| |
2666 | 2666 |
| |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
2667 | 2681 |
| |
2668 | 2682 |
| |
2669 | 2683 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
775 | 775 |
| |
776 | 776 |
| |
777 | 777 |
| |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
778 | 782 |
| |
779 | 783 |
| |
780 | 784 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
567 | 567 |
| |
568 | 568 |
| |
569 | 569 |
| |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
570 | 583 |
| |
571 | 584 |
| |
572 | 585 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
135 | 135 |
| |
136 | 136 |
| |
137 | 137 |
| |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 |
| |
139 | 143 |
| |
140 | 144 |
| |
|
0 commit comments
Comments
(0)