pgsql: Avoid possible dangling-pointer access in tsearch_readline_callb

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Avoid possible dangling-pointer access in tsearch_readline_callb
Дата
Msg-id E1kL6os-00005p-HF@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b91033ae9bc50a2d93656a128eb469bbfaec82a5

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


В списке pgsql-committers по дате отправления:

Предыдущее
От: Thomas Munro
Дата:
Сообщение: pgsql: Allow WaitLatch() to be used without a latch.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Improve error cursor positions for problems with partition bound