Dereferenced pointer in tablesample.c - Mailing list pgsql-hackers

From Michael Paquier
Subject Dereferenced pointer in tablesample.c
Date
Msg-id CAB7nPqSq06h2tVH7RoVnXmj_da4uGzxnk2-JUZnphG1NFqfYuQ@mail.gmail.com
Whole thread Raw
Responses Re: Dereferenced pointer in tablesample.c  (Petr Jelinek <petr@2ndquadrant.com>)
List pgsql-hackers
Hi all,
(Petr in CC)

Coverity is complaining about the following pointer dereference in tablesample_init@tablesample.c:
+               ExprState  *argstate = ExecInitExpr(argexpr, (PlanState *) scanstate);
+
+               if (argstate == NULL)
+               {
+                       fcinfo.argnull[i] = true;
+                       fcinfo.arg[i] = (Datum) 0;;
+               }
+
+               fcinfo.arg[i] = ExecEvalExpr(argstate, econtext,
+                                                                        &fcinfo.argnull[i], NULL);

If the expression argstate is NULL when calling ExecInitExpr(), argstate is going to be NULL and dereferenced afterwards, see execQual.c for more details. Hence I think that the patch attached should be applied. Thoughts?

At the same time I noted a double semicolon, fixed as well in the attached.
Regards,
--
Michael
Attachment

pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Reducing ClogControlLock contention
Next
From: Michael Paquier
Date:
Subject: Re: Reducing ClogControlLock contention