Skip to content

Commit

Permalink
Improve arg handling in continuous_agg_trigfn
Browse files Browse the repository at this point in the history
When continuous_agg_invalidation_trigger is called without any argument,
fcinfo->context in continuous_agg_trigfn is NULL and it should not be
dereferenced.

(cherry picked from commit b514d05)
  • Loading branch information
jnidzwetzki authored and timescale-automation committed Oct 6, 2023
1 parent 2f11814 commit e7cb216
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tsl/src/continuous_aggs/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ continuous_agg_trigfn(PG_FUNCTION_ARGS)
char *hypertable_id_str, *parent_hypertable_id_str;
int32 hypertable_id, parent_hypertable_id = 0;
bool is_distributed_hypertable_trigger = false;
if (trigdata->tg_trigger->tgnargs < 0)

if (trigdata == NULL || trigdata->tg_trigger == NULL || trigdata->tg_trigger->tgnargs < 0)
elog(ERROR, "must supply hypertable id");

hypertable_id_str = trigdata->tg_trigger->tgargs[0];
Expand Down
3 changes: 3 additions & 0 deletions tsl/test/expected/cagg_usage.out
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ SELECT relname FROM pg_class WHERE oid = :mat_table;
----------------------------------------------------------------
-- Cleanup
DROP TABLE whatever;
-- Check that continuous_agg_invalidation_trigger() handles no arguments properly
SELECT _timescaledb_functions.continuous_agg_invalidation_trigger();
ERROR: must supply hypertable id
-- END OF BASIC USAGE TESTS --
CREATE TABLE metrics(time timestamptz, device TEXT, value float);
SELECT table_name FROM create_hypertable('metrics','time');
Expand Down
3 changes: 3 additions & 0 deletions tsl/test/sql/cagg_usage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ SELECT relname FROM pg_class WHERE oid = :mat_table;
-- Cleanup
DROP TABLE whatever;

-- Check that continuous_agg_invalidation_trigger() handles no arguments properly
SELECT _timescaledb_functions.continuous_agg_invalidation_trigger();

-- END OF BASIC USAGE TESTS --

CREATE TABLE metrics(time timestamptz, device TEXT, value float);
Expand Down

0 comments on commit e7cb216

Please sign in to comment.