pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Add recursion depth protections to regular expression matching.
Date: Fri, 02 Oct 2015 18:52:23 +0000
Message-ID: <E1Zi5RP-0000vc-1J@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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_4_STABLE

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

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(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


view thread (7+ messages)  latest in thread

Message-ID: <E1Zi5RP-0000vc-1J@gemulon.postgresql.org>
Permalink:  ../E1Zi5RP-0000vc-1J@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1Zi5RP-0000vc-1J@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Add recursion depth protections to regular expression matching.
  In-Reply-To: <E1Zi5RP-0000vc-1J@gemulon.postgresql.org>
  References: <E1Zi5RP-0000vc-1J@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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