[PATCH] Fix Null pointer dereferences (pgoutput.c)

Started by Ranier Vilelaover 5 years ago2 messages
#1Ranier Vilela
ranier.vf@gmail.com
1 attachment(s)

Hi,

Per Coverity.

If test oldtuple can be NULL, I mean it can really be NULL.
On DELETE process, if oldtuple is NULL, log error and continue.
So UPDATE must have the same treatment.

regards,
Ranier Vilela

Attachments:

fix_null_pointer_dereference_pgoutput.patchapplication/octet-stream; name=fix_null_pointer_dereference_pgoutput.patchDownload
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 77b85fc655..7fb2d31867 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -416,9 +416,9 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
 				break;
 			}
 		case REORDER_BUFFER_CHANGE_UPDATE:
+			if (change->data.tp.oldtuple)
 			{
-				HeapTuple	oldtuple = change->data.tp.oldtuple ?
-				&change->data.tp.oldtuple->tuple : NULL;
+				HeapTuple	oldtuple = &change->data.tp.oldtuple->tuple;
 				HeapTuple	newtuple = &change->data.tp.newtuple->tuple;
 
 				/* Switch relation if publishing via root. */
@@ -437,8 +437,10 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
 				OutputPluginPrepareWrite(ctx, true);
 				logicalrep_write_update(ctx->out, relation, oldtuple, newtuple);
 				OutputPluginWrite(ctx, true);
-				break;
 			}
+			else
+				elog(DEBUG1, "didn't send UPDATE change because of missing oldtuple");
+			break;
 		case REORDER_BUFFER_CHANGE_DELETE:
 			if (change->data.tp.oldtuple)
 			{
#2Amit Langote
amitlangote09@gmail.com
In reply to: Ranier Vilela (#1)
Re: [PATCH] Fix Null pointer dereferences (pgoutput.c)

On Thu, Apr 23, 2020 at 10:48 PM Ranier Vilela <ranier.vf@gmail.com> wrote:

Hi,

Per Coverity.

If test oldtuple can be NULL, I mean it can really be NULL.
On DELETE process, if oldtuple is NULL, log error and continue.
So UPDATE must have the same treatment.

I think I too had noticed this when working on my patch to move this
code to a different location in that function, posted here:
/messages/by-id/CA+HiwqEeU19iQgjN6HF1HTPU0L5+JxyS5CmxaOVGNXBAfUY06Q@mail.gmail.com

--
Amit Langote
EnterpriseDB: http://www.enterprisedb.com