Re: Fix uninitialized variable access (src/backend/utils/mmgr/freepage.c)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix uninitialized variable access (src/backend/utils/mmgr/freepage.c)
Date: 2021-08-18 11:06:18
Message-ID: CAEudQAo-Kn4R8Gxe6YF99vM+d6a3XCjXuidX83OZcYtbQ=mg6Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em qua., 18 de ago. de 2021 às 05:30, Kyotaro Horiguchi <
horikyota(dot)ntt(at)gmail(dot)com> escreveu:

> At Tue, 17 Aug 2021 17:04:44 +0900, Michael Paquier <michael(at)paquier(dot)xyz>
> wrote in
> > On Fri, Jul 02, 2021 at 06:22:56PM -0300, Ranier Vilela wrote:
> > > Em qui., 1 de jul. de 2021 às 17:20, Mahendra Singh Thalor <
> > > mahi6run(at)gmail(dot)com> escreveu:
> > >> Please can we try to hit this rare condition by any test case. If you
> have
> > >> any test cases, please share.
> >
> > Yeah, this needs to be proved. Are you sure that this change is
> > actually right? The bottom of FreePageManagerPutInternal() has
> > assumptions that a page may not be found during a btree search, with
> > an index value used.
>
> By a quick look, FreePageBtreeSearch is called only from
> FreePageManagerPutInternal at three points. The first one assumes that
> result.found == true, at the rest points are passed only when
> fpm->btree_depth > 0, i.e, fpm->btree_root is non-NULL.
>
In short, it's a failure ready to happen, just someone who trusts
FreePageBtreeSearch will do the right thing,
like not leaving structure with uninitialized fields.

> In short FreePageBtreeSeach is never called when fpm->btree_root is
> NULL. I don't think we need to fill-in other members since the
> contract of the function looks fine.
>
Quite the contrary, the contract is not being fulfilled.

> It might be simpler to turn 'if (btp == NULL)' to an assertion.
>
Are you sure that no condition will ever occur in production?
Assertion is not for mistakes that can happen.

regards,
Ranier Vilela

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Денис Романенко 2021-08-18 11:07:46 NAMEDATALEN increase because of non-latin languages
Previous Message Laurenz Albe 2021-08-18 11:06:05 Re: Clarify how triggers relate to transactions