Thread: BUG #18743: /src/backend/rewrite/rewriteHandler.c

BUG #18743: /src/backend/rewrite/rewriteHandler.c

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      18743
Logged by:          Daniel Elishakov
Email address:      dan-eli@mail.ru
PostgreSQL version: 16.4
Operating system:   ubuntu 20.04
Description:

After having been compared to a NULL value at rewriteHandler.c:852, pointer
'(**new_tles[attrno - 1]).expr' is dereferenced at rewriteHandler.c:859.


Re: BUG #18743: /src/backend/rewrite/rewriteHandler.c

From
David Rowley
Date:
On Tue, 10 Dec 2024 at 03:14, PG Bug reporting form
<noreply@postgresql.org> wrote:
> After having been compared to a NULL value at rewriteHandler.c:852, pointer
> '(**new_tles[attrno - 1]).expr' is dereferenced at rewriteHandler.c:859.

I'm not sure if I follow the issue here. At 851 we have:

apply_default = ((new_tle == NULL && commandType == CMD_INSERT) ||
(new_tle && new_tle->expr && IsA(new_tle->expr, SetToDefault)));

and at 859:

if (values_rte && new_tle && IsA(new_tle->expr, Var))

I get that the code is a little convoluted here, but I don't spot the
issue. The "having been compared to a NULL" you mention is for setting
the apply_default variable, and that variable does not have any
influence on the if condition at 859.

Can you specifically state the scenario you think will be handled incorrectly?

David