]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add recursion depth protections to regular expression matching.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 2 Oct 2015 18:51:58 +0000 (14:51 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 2 Oct 2015 18:51:58 +0000 (14:51 -0400)
commita0c089f33f2909663a369eead7877eb6317d31f3
tree09b1f5c6e1d262213c72bb845c3f82f734505d74
parent483bbc9fea18a0bba4d1a28c7e4ed5de5414ca58
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.
src/backend/regex/regc_nfa.c
src/backend/regex/regcomp.c
src/backend/regex/rege_dfa.c
src/backend/regex/regexec.c
src/backend/tcop/postgres.c
src/include/miscadmin.h
src/include/regex/regguts.h