Skip to content

Commit

Permalink
Fix segfault in set_integer_now_func
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lkshminarayanan committed Sep 6, 2023
1 parent e66a400 commit 44e41c1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .unreleased/bugfix_6037
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes: #6045 Fix segfault in set_integer_now_func

Thanks: @alexanderlaw for reporting this issue in set_integer_now_func
1 change: 0 additions & 1 deletion src/hypertable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
3 changes: 3 additions & 0 deletions test/expected/create_hypertable.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/sql/create_hypertable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 44e41c1

Please sign in to comment.