Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c)
| От | Kyotaro Horiguchi |
|---|---|
| Тема | Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c) |
| Дата | |
| Msg-id | 20201102.103610.1084391008125193313.horikyota.ntt@gmail.com обсуждение исходный текст |
| Ответ на | Explicit NULL dereference (src/backend/utils/adt/ruleutils.c) (Ranier Vilela <ranier.vf@gmail.com>) |
| Ответы |
Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c)
Re: Explicit NULL dereference (src/backend/utils/adt/ruleutils.c) |
| Список | 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 по дате отправления: