aboutsummaryrefslogtreecommitdiff
path: root/src/test/modules/test_regex/sql/test_regex.sql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-08-23 17:41:07 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-08-23 17:41:07 -0400
commit779557bd22895420b48eba409d2286f1dea08c06 (patch)
tree399163a9823fd42a39758df315202c78bef06f7e /src/test/modules/test_regex/sql/test_regex.sql
parente3fb6170e58c4325cd1e1eb22f96ef43c3b4152a (diff)
downloadpostgresql-779557bd22895420b48eba409d2286f1dea08c06.tar.gz
postgresql-779557bd22895420b48eba409d2286f1dea08c06.zip
Prevent regexp back-refs from sometimes matching when they shouldn't.
The recursion in cdissect() was careless about clearing match data for capturing parentheses after rejecting a partial match. This could allow a later back-reference to succeed when by rights it should fail for lack of a defined referent. To fix, think a little more rigorously about what the contract between different levels of cdissect's recursion needs to be. With the right spec, we can fix this using fewer rather than more resets of the match data; the key decision being that a failed sub-match is now explicitly responsible for clearing any matches it may have set. There are enough other cross-checks and optimizations in the code that it's not especially easy to exhibit this problem; usually, the match will fail as-expected. Plus, regexps that are even potentially vulnerable are most likely user errors, since there's just not much point 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.us
Diffstat (limited to 'src/test/modules/test_regex/sql/test_regex.sql')
-rw-r--r--src/test/modules/test_regex/sql/test_regex.sql4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/test/modules/test_regex/sql/test_regex.sql b/src/test/modules/test_regex/sql/test_regex.sql
index 9224fdfdd3a..991f804cb67 100644
--- a/src/test/modules/test_regex/sql/test_regex.sql
+++ b/src/test/modules/test_regex/sql/test_regex.sql
@@ -769,6 +769,10 @@ select * from test_regex('^(.+)( \1)+$', 'abc abc abc', 'RP');
select * from test_regex('^(.+)( \1)+$', 'abc abd abc', 'RP');
-- expectNomatch 14.29 RP {^(.+)( \1)+$} {abc abc abd}
select * from test_regex('^(.+)( \1)+$', 'abc abc abd', 'RP');
+-- expectNomatch 14.30 RP {^(.)\1|\1.} {abcdef}
+select * from test_regex('^(.)\1|\1.', 'abcdef', 'RP');
+-- expectNomatch 14.31 RP {^((.)\2|..)\2} {abadef}
+select * from test_regex('^((.)\2|..)\2', 'abadef', 'RP');
-- back reference only matches the string, not any constraints
select * from test_regex('(^\w+).*\1', 'abc abc abc', 'LRP');