Hello everyone,

I'd like to propose adding a check for the nullness of tuplestorestate before 
dereferencing it
in src/backend/executor/nodeModifier.c. The patch is attached.

I am proposing this fix based on the assumption that tuplestorestate could be 
NULL
since there is a check for it when calculating eof_tuplestore at line 85.
However, since this code hasn't been changed since 2006 and hasn't caused any 
issues,
it is possible that the check for (tuplestorestate == NULL) is redundant when 
calculating eof_tuplestore.

--
Best regards,
Alexander Kuznetsov
From b5217fd138f35fb5bf70ad8741ebed5330457891 Mon Sep 17 00:00:00 2001
From: Alexander Kuznetsov <kuznetso...@altlinux.org>
Date: Thu, 10 Oct 2024 17:38:10 +0300
Subject: [PATCH] Check for tuplestorestate nullness before dereferencing

tuplestorestate can be NULL when calculating eof_tuplestore,
where tuplestorestate is dereferenced by tuplestore_gettuple().
Add check for nullness before dereferencing.

Found by ALT Linux Team with Svace.
---
 src/backend/executor/nodeMaterial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/executor/nodeMaterial.c b/src/backend/executor/nodeMaterial.c
index 22e1787fbd..5bc8561f3a 100644
--- a/src/backend/executor/nodeMaterial.c
+++ b/src/backend/executor/nodeMaterial.c
@@ -95,7 +95,7 @@ ExecMaterial(PlanState *pstate)
 			 * to return the one before that, if possible. So do an extra
 			 * fetch.
 			 */
-			if (!tuplestore_advance(tuplestorestate, forward))
+			if (tuplestorestate == NULL || !tuplestore_advance(tuplestorestate, forward))
 				return NULL;	/* the tuplestore must be empty */
 		}
 		eof_tuplestore = false;
-- 
2.42.2

Reply via email to