diff options
| author | Tom Lane | 2013-03-07 16:51:03 +0000 |
|---|---|---|
| committer | Tom Lane | 2013-03-07 16:51:03 +0000 |
| commit | a7b61d4f5af37344f8973b2dfce47e2ba2680061 (patch) | |
| tree | 0af6a1de63f305d5d5b1830369692d422d3a2c57 /src/test | |
| parent | 7ccefe8610db8b339bad2c5b51abc07448a32947 (diff) | |
Fix infinite-loop risk in fixempties() stage of regex compilation.
The previous coding of this function could get into situations where it
would never terminate, because successive passes would re-add EMPTY arcs
that had been removed by the previous pass. Rewrite the function
completely using a new algorithm that is guaranteed to terminate, and
also seems to be usually faster than the old one. Per Tcl bugs 3604074
and 3606683.
Tom Lane and Don Porter
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/regex.out | 20 | ||||
| -rw-r--r-- | src/test/regress/sql/regex.sql | 7 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/test/regress/expected/regex.out b/src/test/regress/expected/regex.out index 658538fd419..757f2a4028a 100644 --- a/src/test/regress/expected/regex.out +++ b/src/test/regress/expected/regex.out @@ -153,3 +153,23 @@ explain (costs off) select * from pg_proc where proname ~ '^(abc)?d'; Filter: (proname ~ '^(abc)?d'::text) (2 rows) +-- Test for infinite loop in pullback() (CVE-2007-4772) +select 'a' ~ '($|^)*'; + ?column? +---------- + t +(1 row) + +-- Test for infinite loop in fixempties() (Tcl bugs 3604074, 3606683) +select 'a' ~ '((((((a)*)*)*)*)*)*'; + ?column? +---------- + t +(1 row) + +select 'a' ~ '((((((a+|)+|)+|)+|)+|)+|)'; + ?column? +---------- + t +(1 row) + diff --git a/src/test/regress/sql/regex.sql b/src/test/regress/sql/regex.sql index c29ed05d768..1426562119a 100644 --- a/src/test/regress/sql/regex.sql +++ b/src/test/regress/sql/regex.sql @@ -34,3 +34,10 @@ explain (costs off) select * from pg_proc where proname ~ '^abc+d'; explain (costs off) select * from pg_proc where proname ~ '^(abc)(def)'; explain (costs off) select * from pg_proc where proname ~ '^(abc)$'; explain (costs off) select * from pg_proc where proname ~ '^(abc)?d'; + +-- Test for infinite loop in pullback() (CVE-2007-4772) +select 'a' ~ '($|^)*'; + +-- Test for infinite loop in fixempties() (Tcl bugs 3604074, 3606683) +select 'a' ~ '((((((a)*)*)*)*)*)*'; +select 'a' ~ '((((((a+|)+|)+|)+|)+|)+|)'; |
