Re: Check for tuplestorestate nullness before dereferencing - Mailing list pgsql-hackers

From Nikolay Shaplov
Subject Re: Check for tuplestorestate nullness before dereferencing
Date
Msg-id 1901674.MHSsGVy7CF@thinkpad-pgpro
Whole thread Raw
In response to Re: Check for tuplestorestate nullness before dereferencing  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
В письме от вторник, 22 апреля 2025 г. 18:50:49 MSK пользователь Tom Lane
написал:

> The reason that the subsequent bit of code is safe is that !forward
> should not possibly be true unless EXEC_FLAG_BACKWARD was given,
> which'd cause us to create a tuplestore.  So if we were going
> to change anything, I'd propose adding something more like
>
>         if (!forward && eof_tuplestore)
>         {
> +               Assert(node->eflags & EXEC_FLAG_BACKWARD);
>                 if (!node->eof_underlying)
>                 {
>                         /*
>
> or perhaps more directly, Assert that tuplestore is not null.

I like  Assert(node->eflags & EXEC_FLAG_BACKWARD);
solution, it gives more information: "here we expect that BACKWARD eflag is
set". (I am not quite familiar with this part of code, this knowledge in not
obvious for me)
While Assert(tuplestorestate != NULL)  gives much less information about what
is happening here.

And I think it is better to add this Assert there. People will continue using
static analyzers on postgres code, finding this place again and again. Better
to close this issue once and for all :-)

--
Nikolay Shaplov aka Nataraj
Fuzzing Engineer at Postgres Professional
Matrix IM: @dhyan:nataraj.su

Attachment

pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: Fortify float4 and float8 regression tests by ordering test results
Next
From: Tom Lane
Date:
Subject: Re: Fortify float4 and float8 regression tests by ordering test results