Make json{b}_populate_recordset() use the right tuple descriptor.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 6 Nov 2017 15:29:16 +0000 (10:29 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 6 Nov 2017 15:29:38 +0000 (10:29 -0500)
commitc30f082d2767c22cefb8875dcb1932e5ed338db6
tree9769364e5db6df43dc5289aa206c9bb655de26f1
parent6b0b983f793b5c9ea68167a408ef58d40b942596
Make json{b}_populate_recordset() use the right tuple descriptor.

json{b}_populate_recordset() used the tuple descriptor created from the
query-level AS clause without worrying about whether it matched the actual
input record type.  If it didn't, that would usually result in a crash,
though disclosure of server memory contents seems possible as well, for a
skilled attacker capable of issuing crafted SQL commands.  Instead, use
the query-supplied descriptor only when there is no input tuple to look at,
and otherwise get a tuple descriptor based on the input tuple's own type
marking.  The core code will detect any type mismatch in the latter case.

Michael Paquier and Tom Lane, per a report from David Rowley.
Back-patch to 9.3 where this functionality was introduced.

Security: CVE-2017-15098
src/backend/utils/adt/jsonfuncs.c
src/test/regress/expected/json.out
src/test/regress/expected/jsonb.out
src/test/regress/sql/json.sql
src/test/regress/sql/jsonb.sql