]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix race condition in DELETE RETURNING.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 10 Mar 2013 23:18:49 +0000 (19:18 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 10 Mar 2013 23:18:49 +0000 (19:18 -0400)
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).

src/backend/executor/nodeModifyTable.c

index cb64cfc857a379d42b20510d8387eec058174e60..d7c1e4a208bf57928ff2dfb4cfa6db89b0586a94 100644 (file)
@@ -439,6 +439,12 @@ ldelete:;
                rslot = ExecProcessReturning(resultRelInfo->ri_projectReturning,
                                                                         slot, planSlot);
 
+               /*
+                * Before releasing the target tuple again, make sure rslot has a
+                * local copy of any pass-by-reference values.
+                */
+               ExecMaterializeSlot(rslot);
+
                ExecClearTuple(slot);
                if (BufferIsValid(delbuffer))
                        ReleaseBuffer(delbuffer);