aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-11-22 15:14:01 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-11-22 15:14:01 -0500
commiteba2ce17121f198316d050e71d8bd049a43783ba (patch)
treefabdf8bd81ae2c19cd5a1bfcfc6e30d36bf0b26c /src/backend/utils/adt/jsonfuncs.c
parentfe375d33a184b98510d08f45f55da1338cde974a (diff)
downloadpostgresql-eba2ce17121f198316d050e71d8bd049a43783ba.tar.gz
postgresql-eba2ce17121f198316d050e71d8bd049a43783ba.zip
Fix another crash in json{b}_populate_recordset and json{b}_to_recordset.
populate_recordset_worker() failed to consider the possibility that the supplied JSON data contains no rows, so that update_cached_tupdesc never got called. This led to a null-pointer dereference since commit 9a5e8ed28; before that it led to a bogus "set-valued function called in context that cannot accept a set" error. Fix by forcing the update to happen. Per bug #15514. Back-patch to v11 as 9a5e8ed28 was. (If we were excited about the bogus error, we could perhaps go back further, but it'd take more work to figure out how to fix it in older branches. Given the lack of field complaints about that aspect, I'm not excited.) Discussion: https://postgr.es/m/15514-59d5b4c4065b178b@postgresql.org
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r--src/backend/utils/adt/jsonfuncs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 0d3e1121cd0..1d63abc11b9 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -3658,6 +3658,12 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
if (PG_ARGISNULL(json_arg_num))
PG_RETURN_NULL();
+ /*
+ * Forcibly update the cached tupdesc, to ensure we have the right tupdesc
+ * to return even if the JSON contains no rows.
+ */
+ update_cached_tupdesc(&cache->c.io.composite, cache->fn_mcxt);
+
state = palloc0(sizeof(PopulateRecordsetState));
/* make tuplestore in a sufficiently long-lived memory context */