pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Prevent regexp back-refs from sometimes matching when they shoul 7+ messages / 1 participants [nested] [flat]
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/08e080756d11c4466b878832f27d741f0507be5a Modified Files -------------- src/backend/regex/regexec.c | 42 ++++++++++++++++++++++++++++++------- src/test/regress/expected/regex.out | 13 ++++++++++++ src/test/regress/sql/regex.sql | 4 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/779557bd22895420b48eba409d2286f1dea08c06 Modified Files -------------- src/backend/regex/regexec.c | 42 +++++++++++++++++----- .../modules/test_regex/expected/test_regex.out | 14 ++++++++ src/test/modules/test_regex/sql/test_regex.sql | 4 +++ src/test/regress/expected/regex.out | 13 +++++++ src/test/regress/sql/regex.sql | 4 +++ 5 files changed, 69 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/9a327179c824712b35eda01a1edef33ad674b188 Modified Files -------------- src/backend/regex/regexec.c | 42 ++++++++++++++++++++++++++++++------- src/test/regress/expected/regex.out | 13 ++++++++++++ src/test/regress/sql/regex.sql | 4 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b9521a1f97e18d4098ce34fd711d24d2064f41c0 Modified Files -------------- src/backend/regex/regexec.c | 42 ++++++++++++++++++++++++++++++------- src/test/regress/expected/regex.out | 13 ++++++++++++ src/test/regress/sql/regex.sql | 4 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/9bbf6f7341f2b5a8ce41d838154380faa7346101 Modified Files -------------- src/backend/regex/regexec.c | 48 ++++++++++++++++------ .../modules/test_regex/expected/test_regex.out | 14 +++++++ src/test/modules/test_regex/sql/test_regex.sql | 4 ++ src/test/regress/expected/regex.out | 13 ++++++ src/test/regress/sql/regex.sql | 4 ++ 5 files changed, 71 insertions(+), 12 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/df87b7c441b1bf2c85f9a753e7750590c19da506 Modified Files -------------- src/backend/regex/regexec.c | 42 ++++++++++++++++++++++++++++++------- src/test/regress/expected/regex.out | 13 ++++++++++++ src/test/regress/sql/regex.sql | 4 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Prevent regexp back-refs from sometimes matching when they shoul @ 2021-08-23 21:41 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2021-08-23 21:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d90e144148885767e2d0a82ccfef75480d39cb8d Modified Files -------------- src/backend/regex/regexec.c | 42 ++++++++++++++++++++++++++++++------- src/test/regress/expected/regex.out | 13 ++++++++++++ src/test/regress/sql/regex.sql | 4 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2021-08-23 21:41 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us> 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us> 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us> 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us> 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us> 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us> 2021-08-23 21:41 pgsql: Prevent regexp back-refs from sometimes matching when they shoul Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox