mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Use portal pinning in PL/Perl and PL/Python
PL/pgSQL "pins" internally generated portals so that user code cannot close them by guessing their names. Add this functionality to PL/Perl and PL/Python as well, preventing users from manually closing cursors created by spi_query and plpy.cursor, respectively. (PL/Tcl does not currently offer any cursor functionality.)
This commit is contained in:
@ -3406,6 +3406,8 @@ plperl_spi_query(char *query)
|
||||
SPI_result_code_string(SPI_result));
|
||||
cursor = cstr2sv(portal->name);
|
||||
|
||||
PinPortal(portal);
|
||||
|
||||
/* Commit the inner transaction, return to outer xact context */
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
@ -3469,6 +3471,7 @@ plperl_spi_fetchrow(char *cursor)
|
||||
SPI_cursor_fetch(p, true, 1);
|
||||
if (SPI_processed == 0)
|
||||
{
|
||||
UnpinPortal(p);
|
||||
SPI_cursor_close(p);
|
||||
row = &PL_sv_undef;
|
||||
}
|
||||
@ -3520,7 +3523,10 @@ plperl_spi_cursor_close(char *cursor)
|
||||
p = SPI_cursor_find(cursor);
|
||||
|
||||
if (p)
|
||||
{
|
||||
UnpinPortal(p);
|
||||
SPI_cursor_close(p);
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
@ -3884,6 +3890,8 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv)
|
||||
|
||||
cursor = cstr2sv(portal->name);
|
||||
|
||||
PinPortal(portal);
|
||||
|
||||
/* Commit the inner transaction, return to outer xact context */
|
||||
ReleaseCurrentSubTransaction();
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
|
Reference in New Issue
Block a user