Re: Fix possible dereference null pointer (PQprint)

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix possible dereference null pointer (PQprint)
Date: 2024-05-31 08:03:24
Message-ID: 18BC1907-1688-463D-8C03-03D64793123A@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 27 May 2024, at 16:52, Ranier Vilela <ranier(dot)vf(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2024-05-31 08:27:42 Re: 001_rep_changes.pl fails due to publisher stuck on shutdown
Previous Message vignesh C 2024-05-31 03:28:16 Re: Ambiguous description on new columns