From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-bugs@postgresql.org
Subject: Re: Crash in json_to_record()
Date: Sun, 23 Feb 2014 19:40:04 -0800
Message-ID: <1393213204.17606.6.camel@jdavis> (raw)
In-Reply-To: <1391797441.15160.41.camel@jdavis>
References: <1391797441.15160.41.camel@jdavis>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Fri, 2014-02-07 at 10:24 -0800, Jeff Davis wrote:
> The attached script crashes on master. It looks like it assumes
> get_call_result_type() always returns a non-NULL tupdesc.
Proposed patch attached; will commit soon unless someone objects.
Checking that get_call_result_type() returns TYPEFUNC_COMPOSITE seems to
be the convention for ensuring the tupdesc is set. I changed the 3 call
sites that do not currently follow that convention (all in jsonfuncs.c).
The other two call sites don't seem to be real problems, but following
the convention seems best.
For the one call site that actually is a problem, I added a HINT to
suggest calling the function from the FROM clause.
Regards,
Jeff Davis
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:json.patch (text/x-patch, 2.4K) download
*** a/src/backend/utils/adt/jsonfuncs.c
--- b/src/backend/utils/adt/jsonfuncs.c
***************
*** 941,947 **** each_worker(PG_FUNCTION_ARGS, bool as_text)
rsi->returnMode = SFRM_Materialize;
! (void) get_call_result_type(fcinfo, NULL, &tupdesc);
/* make these in a sufficiently long-lived memory context */
old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
--- 941,951 ----
rsi->returnMode = SFRM_Materialize;
! if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
! ereport(ERROR,
! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! errmsg("function returning record called in context "
! "that cannot accept type record")));
/* make these in a sufficiently long-lived memory context */
old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
***************
*** 1349,1355 **** populate_record_worker(PG_FUNCTION_ARGS, bool have_record_arg)
json = PG_GETARG_TEXT_P(0);
! get_call_result_type(fcinfo, NULL, &tupdesc);
}
json_hash = get_json_object_as_hash(json, "json_populate_record",
--- 1353,1365 ----
json = PG_GETARG_TEXT_P(0);
! if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
! ereport(ERROR,
! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! errmsg("function returning record called in context "
! "that cannot accept type record"),
! errhint("Try calling the function in the FROM clause "
! "using a column definition list.")));
}
json_hash = get_json_object_as_hash(json, "json_populate_record",
***************
*** 1713,1719 **** populate_recordset_worker(PG_FUNCTION_ARGS, bool have_record_arg)
* get the tupdesc from the result set info - it must be a record type
* because we already checked that arg1 is a record type.
*/
! (void) get_call_result_type(fcinfo, NULL, &tupdesc);
state = palloc0(sizeof(PopulateRecordsetState));
sem = palloc0(sizeof(JsonSemAction));
--- 1723,1733 ----
* get the tupdesc from the result set info - it must be a record type
* because we already checked that arg1 is a record type.
*/
! if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
! ereport(ERROR,
! (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! errmsg("function returning record called in context "
! "that cannot accept type record")));
state = palloc0(sizeof(PopulateRecordsetState));
sem = palloc0(sizeof(JsonSemAction));
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: pgsql@j-davis.com
Subject: Re: Crash in json_to_record()
In-Reply-To: <1393213204.17606.6.camel@jdavis>
References: <1391797441.15160.41.camel@jdavis> <1393213204.17606.6.camel@jdavis>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox