Re: [PATCH] Fix null pointer dereference in PG19 - Mailing list pgsql-hackers

From jian he
Subject Re: [PATCH] Fix null pointer dereference in PG19
Date
Msg-id CACJufxFAs=+CZD5JUa_ZV=8Z--n7QyhaqrnRmypsaBZUxahWYw@mail.gmail.com
Whole thread
In response to Re: [PATCH] Fix null pointer dereference in PG19  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Apr 21, 2026 at 11:24 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> * contain_volatile_functions_after_planning is utterly wrong
> to apply here.  That should happen somewhere in the planner,
> where it'd be cheaper as well as not premature.
>

typedef struct ForPortionOfExpr
{
    NodeTag        type;
    Var           *rangeVar;        /* Range column */
    char       *range_name;        /* Range name */
    Node       *targetFrom;        /* FOR PORTION OF FROM bound, if given */
    Node       *targetTo;        /* FOR PORTION OF TO bound, if given */
    Node       *targetRange;    /* FOR PORTION OF bounds as a
range/multirange */
    Oid            rangeType;        /* (base)type of targetRange */
    bool        isDomain;        /* Is rangeVar a domain? */
    Node       *overlapsExpr;    /* range && targetRange */
    List       *rangeTargetList;    /* List of TargetEntrys to set the time
                                     * column(s) */
    Oid            withoutPortionProc; /* SRF proc for old_range -
target_range */
    ParseLoc    location;        /* token location, or -1 if unknown */
    ParseLoc    targetLocation; /* token location, or -1 if unknown */
} ForPortionOfExpr;

targetFrom and targetTo is only for deparsing purpose, skip
eval_const_expressions should be fine.

RewriteQuery, we have:
``````
AddQual(parsetree, parsetree->forPortionOf->overlapsExpr);
/* Update FOR PORTION OF column(s) automatically. */
foreach(tl, parsetree->forPortionOf->rangeTargetList)
{
    TargetEntry *tle = (TargetEntry *) lfirst(tl);
    parsetree->targetList = lappend(parsetree->targetList, tle);
}
``````
rangeTargetList and overlapsExpr will go through eval_const_expressions.
Only ForPortionOfExpr->targetRange really needs to be dealt with.

In ExecInitModifyTable, we already did
ExecPrepareExpr(forPortionOf->targetRange),
which will do eval_const_expressions(forPortionOf->targetRange).

moving contain_volatile_functions_after_planning to
ExecInitModifyTable should be fine.

In ExecInitModifyTable, we can't just
```
exprState = ExecPrepareExpr((Expr *) forPortionOf->targetRange, estate);
if (contain_volatile_functions_after_planning(exprState->expr)
```

Because of the comments below in execnodes.h:

typedef struct ExprState
    /* original expression tree, for debugging only */
    Expr       *expr;

While at it, add errcode to the surrounding code.



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: [PATCH] Fix hashed ScalarArrayOp semantics for NULL LHS with non-strict comparators
Next
From: "Masashi Kamura (Fujitsu)"
Date:
Subject: RE: ECPG: inconsistent behavior with the document in “GET/SET DESCRIPTOR.”