diff options
author | Pavan Deolasee | 2016-07-11 08:29:50 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 10:07:18 +0000 |
commit | 073288180d1072bd3f1d27e96e89c674cc10d6a6 (patch) | |
tree | 2b07fccd8db67f174a0829a5f741a35cab2a6a95 | |
parent | 77f74072fae3c89ed9ce3b169f1ff1481843158a (diff) |
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.
-rw-r--r-- | src/backend/utils/adt/array_userfuncs.c | 8 | ||||
-rw-r--r-- | src/backend/utils/adt/json.c | 14 | ||||
-rw-r--r-- | src/backend/utils/adt/jsonb.c | 8 | ||||
-rw-r--r-- | src/backend/utils/adt/varlena.c | 15 | ||||
-rw-r--r-- | src/include/utils/json.h | 3 |
5 files changed, 33 insertions, 15 deletions
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c index c14ea23dfb..3eb2505657 100644 --- a/src/backend/utils/adt/array_userfuncs.c +++ b/src/backend/utils/adt/array_userfuncs.c @@ -568,9 +568,11 @@ array_agg_finalfn(PG_FUNCTION_ARGS) ArrayBuildState *state; int dims[1]; int lbs[1]; + 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 : (ArrayBuildState *) PG_GETARG_POINTER(0); @@ -645,9 +647,11 @@ array_agg_array_finalfn(PG_FUNCTION_ARGS) { Datum result; ArrayBuildStateArr *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 : (ArrayBuildStateArr *) PG_GETARG_POINTER(0); 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); diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c index 55bbec9c03..d2b5e1efdc 100644 --- a/src/backend/utils/adt/jsonb.c +++ b/src/backend/utils/adt/jsonb.c @@ -1703,9 +1703,11 @@ jsonb_agg_finalfn(PG_FUNCTION_ARGS) JsonbAggState *arg; JsonbInState result; Jsonb *out; + MemoryContext aggcontext; /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); + if (!AggCheckCallContext(fcinfo, &aggcontext)) + elog(ERROR, "jsonb_agg_finalfn called in non-aggregate context"); if (PG_ARGISNULL(0)) PG_RETURN_NULL(); /* returns null iff no input values */ @@ -1929,9 +1931,11 @@ jsonb_object_agg_finalfn(PG_FUNCTION_ARGS) JsonbAggState *arg; JsonbInState result; Jsonb *out; + MemoryContext aggcontext; /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); + if (!AggCheckCallContext(fcinfo, &aggcontext)) + elog(ERROR, "jsonb_object_agg_finalfn called in non-aggregate context"); if (PG_ARGISNULL(0)) PG_RETURN_NULL(); /* returns null iff no input values */ diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 779729d724..34663f4bba 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -473,9 +473,14 @@ Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS) { StringInfo state; + MemoryContext aggcontext; /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); + if (!AggCheckCallContext(fcinfo, &aggcontext)) + { + /* cannot be called directly because of internal-type argument */ + elog(ERROR, "bytea_string_agg_finalfn called in non-aggregate context"); + } state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0); @@ -4335,9 +4340,13 @@ Datum string_agg_finalfn(PG_FUNCTION_ARGS) { StringInfo state; + MemoryContext aggcontext; - /* cannot be called directly because of internal-type argument */ - Assert(AggCheckCallContext(fcinfo, NULL)); + if (!AggCheckCallContext(fcinfo, &aggcontext)) + { + /* cannot be called directly because of internal-type argument */ + elog(ERROR, "string_agg_finalfn called in non-aggregate context"); + } state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0); diff --git a/src/include/utils/json.h b/src/include/utils/json.h index 11960bbf2c..6743beb219 100644 --- a/src/include/utils/json.h +++ b/src/include/utils/json.h @@ -33,6 +33,9 @@ extern Datum row_to_json_pretty(PG_FUNCTION_ARGS); extern Datum to_json(PG_FUNCTION_ARGS); extern Datum json_agg_transfn(PG_FUNCTION_ARGS); +#ifdef XCP +extern Datum json_agg_collectfn(PG_FUNCTION_ARGS); +#endif extern Datum json_agg_finalfn(PG_FUNCTION_ARGS); extern Datum json_object_agg_finalfn(PG_FUNCTION_ARGS); |