pgsql: Add recursion depth protections to regular expression matching. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Add recursion depth protections to regular expression matching.
Date
Msg-id E1Zi5RP-0000vi-1t@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Add recursion depth protections to regular expression matching.

Some of the functions in regex compilation and execution recurse, and
therefore could in principle be driven to stack overflow.  The Tcl crew
has seen this happen in practice in duptraverse(), though their fix was
to put in a hard-wired limit on the number of recursive levels, which is
not too appetizing --- fortunately, we have enough infrastructure to check
the actually available stack.  Greg Stark has also seen it in other places
while fuzz testing on a machine with limited stack space.  Let's put guards
in to prevent crashes in all these places.

Since the regex code would leak memory if we simply threw elog(ERROR),
we have to introduce an API that checks for stack depth without throwing
such an error.  Fortunately that's not difficult.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/a0c089f33f2909663a369eead7877eb6317d31f3

Modified Files
--------------
src/backend/regex/regc_nfa.c |   68 +++++++++++++++++++++++++++++++++++++-----
src/backend/regex/regcomp.c  |   34 +++++++++++++++++++--
src/backend/regex/rege_dfa.c |    7 +++++
src/backend/regex/regexec.c  |    3 ++
src/backend/tcop/postgres.c  |   39 +++++++++++++-----------
src/include/miscadmin.h      |    1 +
src/include/regex/regguts.h  |    4 +++
7 files changed, 129 insertions(+), 27 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Add recursion depth protections to regular expression matching.
Next
From: Tom Lane
Date:
Subject: pgsql: Add recursion depth protections to regular expression matching.