From 44e41c12ab25e36c202f58e068ced262eadc8d16 Mon Sep 17 00:00:00 2001 From: Lakshmi Narayanan Sreethar Date: Tue, 5 Sep 2023 21:03:21 +0530 Subject: [PATCH] Fix segfault in set_integer_now_func When an invalid function oid is passed to set_integer_now_func, it finds out that the function oid is invalid but before throwing the error, it calls ReleaseSysCache on an invalid tuple causing a segfault. Fixed that by removing the invalid call to ReleaseSysCache. Fixes #6037 --- .unreleased/bugfix_6037 | 3 +++ src/hypertable.c | 1 - test/expected/create_hypertable.out | 3 +++ test/sql/create_hypertable.sql | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .unreleased/bugfix_6037 diff --git a/.unreleased/bugfix_6037 b/.unreleased/bugfix_6037 new file mode 100644 index 00000000000..86f413b8495 --- /dev/null +++ b/.unreleased/bugfix_6037 @@ -0,0 +1,3 @@ +Fixes: #6045 Fix segfault in set_integer_now_func + +Thanks: @alexanderlaw for reporting this issue in set_integer_now_func diff --git a/src/hypertable.c b/src/hypertable.c index f7918f3fc3c..2c40bef16d1 100644 --- a/src/hypertable.c +++ b/src/hypertable.c @@ -2456,7 +2456,6 @@ integer_now_func_validate(Oid now_func_oid, Oid open_dim_type) tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(now_func_oid)); if (!HeapTupleIsValid(tuple)) { - ReleaseSysCache(tuple); ereport(ERROR, (errcode(ERRCODE_NO_DATA_FOUND), errmsg("cache lookup failed for function %u", now_func_oid))); diff --git a/test/expected/create_hypertable.out b/test/expected/create_hypertable.out index f96a7cba4b4..2d6d1081aa4 100644 --- a/test/expected/create_hypertable.out +++ b/test/expected/create_hypertable.out @@ -769,6 +769,9 @@ select set_integer_now_func('test_table_int', 'my_schema.dummy_now2', replace_if ERROR: permission denied for schema my_schema at character 47 select set_integer_now_func('test_table_int', 'dummy_now3', replace_if_exists => TRUE); ERROR: permission denied for function dummy_now3 +-- test invalid oid as the integer_now_func +select set_integer_now_func('test_table_int', 1, replace_if_exists => TRUE); +ERROR: cache lookup failed for function 1 \set ON_ERROR_STOP select set_integer_now_func('test_table_int', 'my_user_schema.dummy_now4', replace_if_exists => TRUE); set_integer_now_func diff --git a/test/sql/create_hypertable.sql b/test/sql/create_hypertable.sql index 520746b16a8..cecff2f7a0e 100644 --- a/test/sql/create_hypertable.sql +++ b/test/sql/create_hypertable.sql @@ -419,6 +419,8 @@ select * from _timescaledb_catalog.dimension WHERE hypertable_id = :TEST_TABLE_I select set_integer_now_func('test_table_int', 'dummy_now'); select set_integer_now_func('test_table_int', 'my_schema.dummy_now2', replace_if_exists => TRUE); select set_integer_now_func('test_table_int', 'dummy_now3', replace_if_exists => TRUE); +-- test invalid oid as the integer_now_func +select set_integer_now_func('test_table_int', 1, replace_if_exists => TRUE); \set ON_ERROR_STOP select set_integer_now_func('test_table_int', 'my_user_schema.dummy_now4', replace_if_exists => TRUE);