]> granicus.if.org Git - postgresql/commitdiff
Protect against XLogReaderAllocate() failing to allocate memory.
authorAndres Freund <andres@anarazel.de>
Thu, 8 Jan 2015 12:35:04 +0000 (13:35 +0100)
committerAndres Freund <andres@anarazel.de>
Thu, 8 Jan 2015 12:35:04 +0000 (13:35 +0100)
logical.c's StartupDecodingContext() forgot to check whether
XLogReaderAllocate() returns NULL indicating a memory allocation
failure.  This could lead, although quite unlikely, lead to a NULL
pointer dereference.

This only applies to 9.4 as earlier versions don't do logical
decoding, and later versions don't return NULL after allocation
failures in XLogReaderAllocate().

Michael Paquier, with minor changes by me.

src/backend/replication/logical/logical.c

index 80b61020bec158e3daa899e3f8b191bd80a7f74a..156c4181eccbfc628dbb30df1549ced295ab97e7 100644 (file)
@@ -162,6 +162,11 @@ StartupDecodingContext(List *output_plugin_options,
        ctx->slot = slot;
 
        ctx->reader = XLogReaderAllocate(read_page, ctx);
+       if (!ctx->reader)
+               ereport(ERROR,
+                               (errcode(ERRCODE_OUT_OF_MEMORY),
+                                errmsg("out of memory")));
+
        ctx->reader->private_data = ctx;
 
        ctx->reorder = ReorderBufferAllocate();