mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +03:00
Prevent possible double-free when update trigger returns old tuple.
This is a variant of the problem fixed in commit25b692568
, which unfortunately we failed to detect at the time. If an update trigger returns the "old" tuple, as it's entitled to do, then a subsequent iteration of the loop in ExecBRUpdateTriggers would have "oldtuple" equal to "trigtuple" and would fail to notice that it shouldn't free that. In addition to fixing the code, extend the test case added by25b692568
so that it covers multiple-trigger-iterations cases. This problem does not manifest in v12/HEAD, as a result of the relevant code having been largely rewritten for slotification. However, include the test case into v12/HEAD anyway, since this is clearly an area that someone could break again in future. Per report from Piotr Gabriel Kosinski. Back-patch into all supported branches, since the bug seems quite old. Diagnosis and code fix by Thomas Munro, test case by me. Discussion: https://postgr.es/m/CAFMLSdP0rd7LqC3j-H6Fh51FYSt5A10DDh-3=W4PPc4LLUQ8YQ@mail.gmail.com
This commit is contained in:
@ -3052,7 +3052,9 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate,
|
||||
relinfo->ri_TrigFunctions,
|
||||
relinfo->ri_TrigInstrument,
|
||||
GetPerTupleMemoryContext(estate));
|
||||
if (oldtuple != newtuple && oldtuple != slottuple)
|
||||
if (oldtuple != newtuple &&
|
||||
oldtuple != slottuple &&
|
||||
oldtuple != trigtuple)
|
||||
heap_freetuple(oldtuple);
|
||||
if (newtuple == NULL)
|
||||
{
|
||||
|
Reference in New Issue
Block a user