From 073288180d1072bd3f1d27e96e89c674cc10d6a6 Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Mon, 11 Jul 2016 13:59:50 +0530 Subject: Change several asserts checking for aggregate context to errors This should address the crash in assert-enabled build reported by Pallavi Sontakke. SQLSmith tries to call various functions from system catalogs and functions should be prepared to handle such calls. --- src/backend/utils/adt/json.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/backend/utils/adt/json.c') diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index d8ae7d3985..773ace3c7b 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -1961,10 +1961,6 @@ json_agg_collectfn(PG_FUNCTION_ARGS) elog(ERROR, "json_agg_collectfn called in non-aggregate context"); } - - /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); - if (PG_ARGISNULL(0)) { /* @@ -2013,11 +2009,12 @@ json_agg_collectfn(PG_FUNCTION_ARGS) Datum json_agg_finalfn(PG_FUNCTION_ARGS) { - JsonAggState *state; + JsonAggState *state; MemoryContext aggcontext; /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); + if (!AggCheckCallContext(fcinfo, &aggcontext)) + elog(ERROR, "aggregate function called in non-aggregate context"); state = PG_ARGISNULL(0) ? NULL : @@ -2130,11 +2127,12 @@ json_object_agg_transfn(PG_FUNCTION_ARGS) Datum json_object_agg_finalfn(PG_FUNCTION_ARGS) { - JsonAggState *state; + JsonAggState *state; MemoryContext aggcontext; /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); + if (!AggCheckCallContext(fcinfo, &aggcontext)) + elog(ERROR, "aggregate function called in non-aggregate context"); state = PG_ARGISNULL(0) ? NULL : (JsonAggState *) PG_GETARG_POINTER(0); -- cgit v1.2.3