8000 Fix race condition in DELETE RETURNING. · danielcode/postgres@3263896 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3263896

Browse files
committed
Fix race condition in DELETE RETURNING.
When RETURNING is specified, ExecDelete would return a virtual-tuple slot that could contain pointers into an already-unpinned disk buffer. Another process could change the buffer contents before we get around to using the data, resulting in garbage results or even a crash. This seems of fairly low probability, which may explain why there are no known field reports of the problem, but it's definitely possible. Fix by forcing the result slot to be "materialized" before we release pin on the disk buffer. Back-patch to 9.0; in earlier branches there is no bug because ExecProcessReturning sent the tuple to the destination immediately. Also, this is already fixed in HEAD as part of the writable-foreign-tables patch (where the fix is necessary for DELETE RETURNING to work at all with postgres_fdw).
1 parent 957b9c0 commit 3263896

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ ldelete:;
440440
rslot = ExecProcessReturning(resultRelInfo->ri_projectReturning,
441441
slot, planSlot);
442442

443+
/*
444+
* Before releasing the target tuple again, make sure rslot has a
445+
* local copy of any pass-by-reference values.
446+
*/
447+
ExecMaterializeSlot(rslot);
448+
443449
ExecClearTuple(slot);
444450
if (BufferIsValid(delbuffer))
445451
ReleaseBuffer(delbuffer);

0 commit comments

Comments
 (0)
0