Re: Fix possible dereference null pointer (PQprint) - Mailing list pgsql-hackers

From Daniel Gustafsson
Subject Re: Fix possible dereference null pointer (PQprint)
Date
Msg-id 18BC1907-1688-463D-8C03-03D64793123A@yesql.se
Whole thread Raw
In response to Fix possible dereference null pointer (PQprint)  (Ranier Vilela <ranier.vf@gmail.com>)
Responses Re: Fix possible dereference null pointer (PQprint)
List pgsql-hackers
> On 27 May 2024, at 16:52, Ranier Vilela <ranier.vf@gmail.com> wrote:

> In the function *PQprint*, the variable po->fieldName can be NULL.

Yes.

> See the checks a few lines up.

Indeed, let's check it.

        for (numFieldName = 0;
             po->fieldName && po->fieldName[numFieldName];
             numFieldName++)
            ;
        for (j = 0; j < nFields; j++)
        {
            int         len;
            const char *s = (j < numFieldName && po->fieldName[j][0]) ?
                po->fieldName[j] : PQfname(res, j);

If po->fieldName is NULL then numFieldName won't be incremented and will remain
zero.  In the check you reference we check (j < numFieldName) which will check
the j in the range 0..nFields for being less than zero.  The code thus does
seem quite correct to me.

--
Daniel Gustafsson




pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: Use generation memory context for tuplestore.c
Next
From: Peter Smith
Date:
Subject: Re: 001_rep_changes.pl fails due to publisher stuck on shutdown