Fix possible dereference null pointer (PQprint)
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t49695psql -h localhost -U postgresBuilt from patchset v1 (message #1), September 20, 2026 at 10:16 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t49695_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t49695_1 && git checkout t49695_1Patchset v1 (message #1) is on t49695_1
Hi.
In the function *PQprint*, the variable po->fieldName
can be NULL.
See the checks a few lines up.
for (numFieldName = 0;
po->fieldName && po->fieldName[numFieldName];
numFieldName++)
So, I think that must be checked, when used,
in the loop below.
best regards,
Ranier Vilela
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
Em sex., 31 de mai. de 2024 às 05:03, Daniel Gustafsson <daniel@yesql.se>
escreveu:
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.
You are completely correct. My bad.
Thank you Daniel.
best regards,
Ranier Vilela