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@lists.postgresql.org
Subject: pgsql: Avoid possible dangling-pointer access in tsearch_readline_callb
Date: Wed, 23 Sep 2020 15:36:34 +0000
Message-ID: <E1kL6os-00005v-I1@gemulon.postgresql.org> (raw)

Avoid possible dangling-pointer access in tsearch_readline_callback.

tsearch_readline() saves the string pointer it returns to the caller
for possible use in the associated error context callback.  However,
the caller will usually pfree that string sometime before it next
calls tsearch_readline(), so that there is a window where an ereport
will try to print an already-freed string.

The built-in users of tsearch_readline() happen to all do that pfree
at the bottoms of their loops, so that the window is effectively
empty for them.  However, this is not documented as a requirement,
and contrib/dict_xsyn doesn't do it like that, so it seems likely
that third-party dictionaries might have live bugs here.

The practical consequences of this seem pretty limited in any case,
since production builds wouldn't clobber the freed string immediately,
besides which you'd not expect syntax errors in dictionary files
being used in production.  Still, it's clearly a bug waiting to bite
somebody.

Fix by pstrdup'ing the string to be saved for the error callback,
and then pfree'ing it next time through.  It's been like this for
a long time, so back-patch to all supported branches.

Discussion: https://postgr.es/m/48A4FA71-524E-41B9-953A-FD04EF36E2E7@yesql.se

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/61cfd90621d6c40ada0d0f8a7ca68bf564bf983d

Modified Files
--------------
src/backend/tsearch/ts_locale.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1kL6os-00005v-I1@gemulon.postgresql.org>
Permalink:  ../E1kL6os-00005v-I1@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kL6os-00005v-I1@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: Avoid possible dangling-pointer access in tsearch_readline_callb
  In-Reply-To: <E1kL6os-00005v-I1@gemulon.postgresql.org>
  References: <E1kL6os-00005v-I1@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