postgres.git / summary / log / commit / refs

commit    90abbba07460580616ab2b351d3512e67f43ad83
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Tue Apr 21 18:23:42 2020 +0000
First released in: 13.0, 9.6.18, 10.13, 11.8, 12.3

    Fix minor violations of FunctionCallInvoke usage protocol.
    
    Working on commit 1c455078b led me to check through FunctionCallInvoke
    call sites to see if every one was being honest about (a) making sure
    that fcinfo.isnull is initially false, and (b) checking its state after
    the call.  Sure enough, I found some violations.
    
    The main one is that finalize_partialaggregate re-used serialfn_fcinfo
    without resetting isnull, even though it clearly intends to cater for
    serialfns that return NULL.  There would only be an issue with a
    non-strict serialfn, since it's unlikely that a serialfn would return
    NULL for non-null input.  We have no non-strict serialfns in core, and
    there may be none in the wild either, which would account for the lack
    of complaints.  Still, it's clearly wrong, so back-patch that fix to
    9.6 where finalize_partialaggregate was introduced.
    
    Also, arrayfuncs.c and rowtypes.c contained various callers that were
    not bothering to check for result nulls.  While what's being called is
    a comparison or hash function that probably *shouldn't* return null,
    that's a lousy excuse for not having any check at all.  There are
    existing places that just Assert(!fcinfo->isnull) in comparable
    situations, so I added that to the places that were calling btree
    comparison or hash support functions.  In the places calling
    boolean-returning equality functions, it's quite cheap to have them
    treat isnull as FALSE, so make those places do that.  Also remove some
    "locfcinfo->isnull = false" assignments that are unnecessary given the
    assumption that no previous call returned null.  These changes seem like
    mostly neatnik-ism or debugging support, so I didn't back-patch.


src/backend/executor/nodeAgg.c | 1 + src/include/fmgr.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index eef0e8437de..bdc17a5a64b 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -1014,6 +1014,7 @@ finalize_partialaggregate(AggState *aggstate, pergroupstate->transValueIsNull, pertrans->transtypeLen); fcinfo->args[0].isnull = pergroupstate->transValueIsNull; + fcinfo->isnull = false; *resultVal = FunctionCallInvoke(fcinfo); *resultIsNull = fcinfo->isnull; diff --git a/src/include/fmgr.h b/src/include/fmgr.h index 3ff099986b8..f61757373bc 100644 --- a/src/include/fmgr.h +++ b/src/include/fmgr.h @@ -163,6 +163,11 @@ extern void fmgr_symbol(Oid functionId, char **mod, char **fn); * caller must still check fcinfo->isnull! Also, if function is strict, * it is caller's responsibility to verify that no null arguments are present * before calling. + * + * Some code performs multiple calls without redoing InitFunctionCallInfoData, + * possibly altering the argument values. This is okay, but be sure to reset + * the fcinfo->isnull flag before each call, since callees are permitted to + * assume that starts out false. */ #define FunctionCallInvoke(fcinfo) ((* (fcinfo)->flinfo->fn_addr) (fcinfo)) [parent: e26c8a6b31e9]