diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2023-04-16 14:16:40 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2023-04-16 14:16:40 -0400 |
commit | 78d5952dd0e66afc4447eec07f770991fa406cce (patch) | |
tree | d2be84d4bcfb7230bc2957aa4b1daf3789a2cadb /src/backend/executor/nodeWindowAgg.c | |
parent | 1c54b93a8cf959a826dfabd6cae55dce255df2f5 (diff) | |
download | postgresql-78d5952dd0e66afc4447eec07f770991fa406cce.tar.gz postgresql-78d5952dd0e66afc4447eec07f770991fa406cce.zip |
Ensure result of an aggregate's finalfunc is made read-only.
The finalfunc might return a read-write expanded object. If we
de-duplicate multiple call sites for the aggregate, any function(s)
receiving the aggregate result earlier could alter or destroy the
value that reaches the ones called later. This is a brown-paper-bag
bug in commit 42b746d4c, because we actually considered the need
for read-only-ness but failed to realize that it applied to the case
with a finalfunc as well as the case without.
Per report from Justin Pryzby. New error in HEAD,
no need for back-patch.
Discussion: https://postgr.es/m/ZDm5TuKsh3tzoEjz@telsasoft.com
Diffstat (limited to 'src/backend/executor/nodeWindowAgg.c')
-rw-r--r-- | src/backend/executor/nodeWindowAgg.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 7c07fb06848..3ac581a7113 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -623,10 +623,15 @@ finalize_windowaggregate(WindowAggState *winstate, } else { + Datum res; + winstate->curaggcontext = peraggstate->aggcontext; - *result = FunctionCallInvoke(fcinfo); + res = FunctionCallInvoke(fcinfo); winstate->curaggcontext = NULL; *isnull = fcinfo->isnull; + *result = MakeExpandedObjectReadOnly(res, + fcinfo->isnull, + peraggstate->resulttypeLen); } } else |