mirror of
https://github.com/postgres/postgres.git
synced 2025-05-12 16:21:30 +03:00
Fix use-after-free bug with event triggers and ALTER TABLE.
EventTriggerAlterTableEnd neglected to make sure that it built its output list in the right context. In simple cases this was masked because the function is called in PortalContext which will be sufficiently long-lived anyway; but that doesn't make it not a bug. Commit ced138e8c fixed this in HEAD and v13, but mistakenly chose not to back-patch further. Back-patch the same code change all the way (I didn't bother with the test case though, as it would prove nothing in pre-v13 branches). Per report from Arseny Sher. Original fix by Jehan-Guillaume de Rorthais. Discussion: https://postgr.es/m/877drcyprb.fsf@ars-thinkpad Discussion: https://postgr.es/m/20200902193715.6e0269d4@firost
This commit is contained in:
parent
197014baa4
commit
93f726c04f
@ -1807,9 +1807,15 @@ EventTriggerAlterTableEnd(void)
|
|||||||
/* If no subcommands, don't collect */
|
/* If no subcommands, don't collect */
|
||||||
if (list_length(currentEventTriggerState->currentCommand->d.alterTable.subcmds) != 0)
|
if (list_length(currentEventTriggerState->currentCommand->d.alterTable.subcmds) != 0)
|
||||||
{
|
{
|
||||||
|
MemoryContext oldcxt;
|
||||||
|
|
||||||
|
oldcxt = MemoryContextSwitchTo(currentEventTriggerState->cxt);
|
||||||
|
|
||||||
currentEventTriggerState->commandList =
|
currentEventTriggerState->commandList =
|
||||||
lappend(currentEventTriggerState->commandList,
|
lappend(currentEventTriggerState->commandList,
|
||||||
currentEventTriggerState->currentCommand);
|
currentEventTriggerState->currentCommand);
|
||||||
|
|
||||||
|
MemoryContextSwitchTo(oldcxt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pfree(currentEventTriggerState->currentCommand);
|
pfree(currentEventTriggerState->currentCommand);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user