pgsql: Save/restore SPI's global variables in SPI_connect() andSPI_fin

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Save/restore SPI's global variables in SPI_connect() andSPI_fin
Дата
Msg-id E1fyQpQ-0007Ue-9o@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Save/restore SPI's global variables in SPI_connect() and SPI_finish().

This patch removes two sources of interference between nominally
independent functions when one SPI-using function calls another,
perhaps without knowing that it does so.

Chapman Flack pointed out that xml.c's query_to_xml_internal() expects
SPI_tuptable and SPI_processed to stay valid across datatype output
function calls; but it's possible that such a call could involve
re-entrant use of SPI.  It seems likely that there are similar hazards
elsewhere, if not in the core code then in third-party SPI users.
Previously SPI_finish() reset SPI's API globals to zeroes/nulls, which
would typically make for a crash in such a situation.  Restoring them
to the values they had at SPI_connect() seems like a considerably more
useful behavior, and it still meets the design goal of not leaving any
dangling pointers to tuple tables of the function being exited.

Also, cause SPI_connect() to reset these variables to zeroes/nulls after
saving them.  This prevents interference in the opposite direction: it's
possible that a SPI-using function that's only ever been tested standalone
contains assumptions that these variables start out as zeroes.  That was
the case as long as you were the outermost SPI user, but not so much for
an inner user.  Now it's consistent.

Report and fix suggestion by Chapman Flack, actual patch by me.
Back-patch to all supported branches.

Discussion: https://postgr.es/m/9fa25bef-2e4f-1c32-22a4-3ad0723c4a17@anastigmatix.net

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0254aa83b57abb4e971f6b225cc4678c782fdf51

Modified Files
--------------
src/backend/executor/spi.c      | 42 ++++++++++++++++++++++++++++++++---------
src/include/executor/spi_priv.h |  6 ++++++
2 files changed, 39 insertions(+), 9 deletions(-)


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Limit depth of forced recursion for CLOBBER_CACHE_RECURSIVELY.
Следующее
От: Michael Paquier
Дата:
Сообщение: pgsql: Remove duplicated words split across lines in comments