]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Compute aggregate argument types correctly in transformAggregateCall().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 6 Nov 2023 15:38:00 +0000 (10:38 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 6 Nov 2023 15:38:00 +0000 (10:38 -0500)
commit8c6633f4deb6ace445fc3d72d54585c373187d2d
treecae4ddb016739a574558e19334162296b63d279b
parenta27be40c1bc328f4bab324ccecd601909ec94ac9
Compute aggregate argument types correctly in transformAggregateCall().

transformAggregateCall() captures the datatypes of the aggregate's
arguments immediately to construct the Aggref.aggargtypes list.
This seems reasonable because the arguments have already been
transformed --- but there is an edge case where they haven't been.
Specifically, if we have an unknown-type literal in an ANY argument
position, nothing will have been done with it earlier.  But if we
also have DISTINCT, then addTargetToGroupList() converts the literal
to "text" type, resulting in the aggargtypes list not matching the
actual runtime type of the argument.  The end result is that the
aggregate tries to interpret a "text" value as being of type
"unknown", that is a zero-terminated C string.  If the text value
contains no zero bytes, this could result in disclosure of server
memory following the text literal value.

To fix, move the collection of the aggargtypes list to the end
of transformAggregateCall(), after DISTINCT has been handled.
This requires slightly more code, but not a great deal.

Our thanks to Jingzhou Fu for reporting this problem.

Security: CVE-2023-5868
src/backend/parser/parse_agg.c
src/test/regress/expected/jsonb.out
src/test/regress/sql/jsonb.sql