aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2022-11-25 09:00:15 +0530
committerAmit Kapila <akapila@postgresql.org>2022-11-25 09:00:15 +0530
commitaa9d916f671de1decdc3978b952ed0ab2670d2ed (patch)
tree7cf9d7e565b10aa29484fe2eb0093b41984a2ab2 /src
parentde95928ea071b5c677ceaa0d13d4ea15d88cec43 (diff)
downloadpostgresql-aa9d916f671de1decdc3978b952ed0ab2670d2ed.tar.gz
postgresql-aa9d916f671de1decdc3978b952ed0ab2670d2ed.zip
Fix uninitialized access to InitialRunningXacts during decoding.
In commit 272248a0c, we introduced an InitialRunningXacts array to remember transactions and subtransactions that were running when the xl_running_xacts record that we decoded was written. This array was allocated in the snapshot builder memory context after we restore serialized snapshot but we forgot to reset the array while freeing the builder memory context. So, the next time when we start decoding in the same session where we don't restore any serialized snapshot, we ended up using the uninitialized array and that can lead to unpredictable behavior. This problem doesn't exist in HEAD as instead of using InitialRunningXacts, we added the list of transaction IDs and sub-transaction IDs, that have modified catalogs and are running during snapshot serialization, to the serialized snapshot (see commit 7f13ac8123). Reported-by: Maxim Orlov Author: Masahiko Sawada Reviewed-by: Amit Kapila, Maxim Orlov Backpatch-through: 11 Discussion: https://postgr.es/m/CACG=ezZoz_KG+Ryh9MrU_g5e0HiVoHocEvqFF=NRrhrwKmEQJQ@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/logical/snapbuild.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index d1a279c5a98..859ba4c6943 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -376,6 +376,9 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
MemoryContextSwitchTo(oldcontext);
+ /* The initial running transactions array must be empty. */
+ Assert(NInitialRunningXacts == 0 && InitialRunningXacts == NULL);
+
return builder;
}
@@ -396,6 +399,10 @@ FreeSnapshotBuilder(SnapBuild *builder)
/* other resources are deallocated via memory context reset */
MemoryContextDelete(context);
+
+ /* InitialRunningXacts is freed along with the context */
+ NInitialRunningXacts = 0;
+ InitialRunningXacts = NULL;
}
/*