mirror of
https://github.com/postgres/postgres.git
synced 2025-08-18 12:22:09 +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:
@@ -151,6 +151,8 @@ PLy_cursor_query(const char *query)
|
||||
|
||||
cursor->portalname = MemoryContextStrdup(cursor->mcxt, portal->name);
|
||||
|
||||
PinPortal(portal);
|
||||
|
||||
PLy_spi_subtransaction_commit(oldcontext, oldowner);
|
||||
}
|
||||
PG_CATCH();
|
||||
@@ -266,6 +268,8 @@ PLy_cursor_plan(PyObject *ob, PyObject *args)
|
||||
|
||||
cursor->portalname = MemoryContextStrdup(cursor->mcxt, portal->name);
|
||||
|
||||
PinPortal(portal);
|
||||
|
||||
PLy_spi_subtransaction_commit(oldcontext, oldowner);
|
||||
}
|
||||
PG_CATCH();
|
||||
@@ -317,7 +321,10 @@ PLy_cursor_dealloc(PyObject *arg)
|
||||
portal = GetPortalByName(cursor->portalname);
|
||||
|
||||
if (PortalIsValid(portal))
|
||||
{
|
||||
UnpinPortal(portal);
|
||||
SPI_cursor_close(portal);
|
||||
}
|
||||
cursor->closed = true;
|
||||
}
|
||||
if (cursor->mcxt)
|
||||
@@ -508,6 +515,7 @@ PLy_cursor_close(PyObject *self, PyObject *unused)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UnpinPortal(portal);
|
||||
SPI_cursor_close(portal);
|
||||
cursor->closed = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user