Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c) - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c)
Date
Msg-id 20201102.103610.1084391008125193313.horikyota.ntt@gmail.com
Whole thread Raw
In response to Explicit NULL dereference (src/backend/utils/adt/ruleutils.c)  (Ranier Vilela <ranier.vf@gmail.com>)
Responses Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c)  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c)  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
List pgsql-hackers
At Sat, 31 Oct 2020 11:49:07 -0300, Ranier Vilela <ranier.vf@gmail.com> wrote in 
> Per Coverity.
> 
> make_ruledef function can dereference a NULL pointer (actions),
> if "ev_qual" is provided and "actions" does not exist.
> 
> The comment there is contradictory: " /* these could be nulls */ "
> Because if "ev_qual" is not null, "actions" cannot be either.
> 
> Solution proposed merely as a learning experience.

We cannot reach there with ev_action == NULL since it comes from a
non-nullable column. Since most of the other columns has an assertion
that !isnull, I think we should do the same thing for ev_action (and
ev_qual).  SPI_getvalue() returns C-NULL for SQL-NULL (or for some
other unexpected situations.).

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6c656586e8..6ba2b4a5ae 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -4766,12 +4766,13 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
     /* these could be nulls */
     fno = SPI_fnumber(rulettc, "ev_qual");
     ev_qual = SPI_getvalue(ruletup, rulettc, fno);
+    Assert(ev_qual != NULL);
 
     fno = SPI_fnumber(rulettc, "ev_action");
     ev_action = SPI_getvalue(ruletup, rulettc, fno);
-    if (ev_action != NULL)
-        actions = (List *) stringToNode(ev_action);
-
+    Assert(ev_action != NULL);
+    actions = (List *) stringToNode(ev_action);
+        
     ev_relation = table_open(ev_class, AccessShareLock);
 
     /*

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Online checksums verification in the backend
Next
From: Andres Freund
Date:
Subject: Re: Online checksums verification in the backend