Thread: [PATCH] Fix Uninitialized scalar variable (UNINIT) (src/backend/access/heap/heapam_handler.c)

Hi Tom,

Per Coverity.

The variable root_offsets is read at line 1641, but, at this point,
the content is unknown, so it is impossible to test works well.

regards,
Ranier Vilela
Attachment
On 2020-Aug-25, Ranier Vilela wrote:

> The variable root_offsets is read at line 1641, but, at this point,
> the content is unknown, so it is impossible to test works well.

Surely it is set by heap_get_root_tuples() in line 1347?  The root_blkno
variable is used exclusively to know whether root_offsets has been
initialized for the current block.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Em ter., 25 de ago. de 2020 às 18:06, Alvaro Herrera <alvherre@2ndquadrant.com> escreveu:
On 2020-Aug-25, Ranier Vilela wrote:

> The variable root_offsets is read at line 1641, but, at this point,
> the content is unknown, so it is impossible to test works well.

Surely it is set by heap_get_root_tuples() in line 1347?  The root_blkno
variable is used exclusively to know whether root_offsets has been
initialized for the current block.
Hi Álvaro,

20. Condition hscan->rs_cblock != root_blkno, taking false branch.

If the variable hscan->rs_cblock is InvalidBlockNumber the test can
protect root_offsets fail.

The var root_blkno only is checked at line 1853.

regards,
Ranier Vilela

On 2020-Aug-25, Ranier Vilela wrote:

> If the variable hscan->rs_cblock is InvalidBlockNumber the test can
> protect root_offsets fail.

When does that happen?

> The var root_blkno only is checked at line 1853.

That's a different function.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Em ter., 25 de ago. de 2020 às 19:45, Alvaro Herrera <alvherre@2ndquadrant.com> escreveu:
On 2020-Aug-25, Ranier Vilela wrote:

> If the variable hscan->rs_cblock is InvalidBlockNumber the test can
> protect root_offsets fail.

When does that happen?
At first pass into the while loop?
hscan->rs_cblock is InvalidBlockNumber, what happens?


> The var root_blkno only is checked at line 1853.

That's a different function.
My mistake. Find editor.

regards,
Ranier Vilela
Em ter., 25 de ago. de 2020 às 19:54, Ranier Vilela <ranier.vf@gmail.com> escreveu:
Em ter., 25 de ago. de 2020 às 19:45, Alvaro Herrera <alvherre@2ndquadrant.com> escreveu:
On 2020-Aug-25, Ranier Vilela wrote:

> If the variable hscan->rs_cblock is InvalidBlockNumber the test can
> protect root_offsets fail.

When does that happen?
At first pass into the while loop?
hscan->rs_cblock is InvalidBlockNumber, what happens?

Other things.
1. Even heap_get_root_tuples at line 1347, be called.
Does it fill all roots_offsets?
root_offsets[offnum - 1] is secure at this point (line 1641 or is trash)?

2. hscan->rs_cbuf is constant?
if (hscan->rs_cblock != root_blkno)
{
Page page = BufferGetPage(hscan->rs_cbuf);

LockBuffer(hscan->rs_cbuf, BUFFER_LOCK_SHARE);
heap_get_root_tuples(page, root_offsets);
LockBuffer(hscan->rs_cbuf, BUFFER_LOCK_UNLOCK);

root_blkno = hscan->rs_cblock;
}

This can move outside while loop?
Am I wrong or hscan do not change?

regards,
Ranier Vilela


On 2020-Aug-25, Ranier Vilela wrote:

> Em ter., 25 de ago. de 2020 às 19:45, Alvaro Herrera <
> alvherre@2ndquadrant.com> escreveu:
> 
> > On 2020-Aug-25, Ranier Vilela wrote:
> >
> > > If the variable hscan->rs_cblock is InvalidBlockNumber the test can
> > > protect root_offsets fail.
> >
> > When does that happen?
>
> At first pass into the while loop?
> hscan->rs_cblock is InvalidBlockNumber, what happens?

No, it is set when the page is read.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




Em ter., 25 de ago. de 2020 às 20:13, Alvaro Herrera <alvherre@2ndquadrant.com> escreveu:
On 2020-Aug-25, Ranier Vilela wrote:

> Em ter., 25 de ago. de 2020 às 19:45, Alvaro Herrera <
> alvherre@2ndquadrant.com> escreveu:
>
> > On 2020-Aug-25, Ranier Vilela wrote:
> >
> > > If the variable hscan->rs_cblock is InvalidBlockNumber the test can
> > > protect root_offsets fail.
> >
> > When does that happen?
>
> At first pass into the while loop?
> hscan->rs_cblock is InvalidBlockNumber, what happens?

No, it is set when the page is read.
And it is guaranteed that, rs_cblock is not InvalidBlockNumber when the page is read?

Ranier Vilela
On 2020-Aug-25, Ranier Vilela wrote:

> 1. Even heap_get_root_tuples at line 1347, be called.
> Does it fill all roots_offsets?

Yes -- read the comments there.

> 2. hscan->rs_cbuf is constant?
> if (hscan->rs_cblock != root_blkno)

It is the buffer that contains the given block.  Those two things move
in unison.  See heapgettup and heapgettup_pagemode.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



On 2020-Aug-25, Ranier Vilela wrote:

> And it is guaranteed that, rs_cblock is not InvalidBlockNumber when the
> page is read?

It could be InvalidBlockNumber if sufficient neutrinos hit the memory
bank and happen to set all the bits in the block number.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Em ter., 25 de ago. de 2020 às 20:20, Alvaro Herrera <alvherre@2ndquadrant.com> escreveu:
On 2020-Aug-25, Ranier Vilela wrote:

> And it is guaranteed that, rs_cblock is not InvalidBlockNumber when the
> page is read?

It could be InvalidBlockNumber if sufficient neutrinos hit the memory
bank and happen to set all the bits in the block number.
kkk, I think it's enough for me.
I believe that PostgreSQL will not run on the ISS yet.

Ranier Vilela
On 2020-Aug-25, Ranier Vilela wrote:

> kkk, I think it's enough for me.
> I believe that PostgreSQL will not run on the ISS yet.

Actually, I believe there are some satellites that run Postgres -- not
100% sure about this.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Em ter., 25 de ago. de 2020 às 20:29, Alvaro Herrera <alvherre@2ndquadrant.com> escreveu:
On 2020-Aug-25, Ranier Vilela wrote:

> kkk, I think it's enough for me.
> I believe that PostgreSQL will not run on the ISS yet.

Actually, I believe there are some satellites that run Postgres -- not
100% sure about this.
Yeah, ESA uses:

In fact, Postgres is to be congratulated.
Guess who didn't make any bug?
"Sqirrel has successfully detected 63 bugs from tested DBMS,including 51 bugs from SQLite, 7 from MySQL, and 5 from MariaDB."

Ranier Vilela