Re: BUG #18785: Pointer bmr.rel, dereferenced by passing as 1st parameter to function is checked for NULL later - Mailing list pgsql-bugs

From Andres Freund
Subject Re: BUG #18785: Pointer bmr.rel, dereferenced by passing as 1st parameter to function is checked for NULL later
Date
Msg-id a6oxxee6blexicuark46yydtaqulsjvkrwkri6aic4vbofjxse@4a6j4kuwda7u
Whole thread Raw
In response to BUG #18785: Pointer bmr.rel, dereferenced by passing as 1st parameter to function is checked for NULL later  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18785: Pointer bmr.rel, dereferenced by passing as 1st parameter to function is checked for NULL later
List pgsql-bugs
Hi,

On 2025-01-28 13:58:13 +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      18785
> Logged by:          Daniel Elishakov
> Email address:      dan-eli@mail.ru
> PostgreSQL version: 16.6
> Operating system:   ubuntu 20.04
> Description:        

I don't think it's particularly useful to report missing assertions as bugs,
particularly not multiple bugs for basically the same issue.


> Hello, I suggest the following patch for this issue.
> 
> @@ -905,6 +905,8 @@ ExtendBufferedRelTo(BufferManagerRelation bmr,
>                  bmr.smgr->smgr_cached_nblocks[fork] == InvalidBlockNumber)
> &&
>                 !smgrexists(bmr.smgr, fork))
>         {
> +
> +               Assert(bmr.rel != NULL);
>                 LockRelationForExtension(bmr.rel, ExclusiveLock);
>  
>                 /* could have been closed while waiting for lock */
> 
> 
> I think we need to check bmr.rel for NULL, because Asserts above do not
> suggest bmr.rel != NULL. Moreover, it is being checked for NULL later after
> being passed into function LockRelationForExtension(bmr.rel, ExclusiveLock);

I guess it couldn't hurt to add them. It's fine for existing callers...

The specific suggested assertion seems not great, because it'll often not even
be reached, due to the file not being empty.

I think it'd be better to assert something like

/* EB_CREATE_FORK_IF_NEEDED is currently only needed with extension lock */
Assert(!(flags & EB_CREATE_FORK_IF_NEEDED) || !(flags & EB_SKIP_EXTENSION_LOCK));

/* can only acquire extension lock if rel is passed in */
Assert(bmr.rel != NULL || (flags & EB_SKIP_EXTENSION_LOCK));

Greetings,

Andres Freund



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #18787: pointer te->defn not checked for NULL
Next
From: Tom Lane
Date:
Subject: Re: BUG #18785: Pointer bmr.rel, dereferenced by passing as 1st parameter to function is checked for NULL later