Skip to content

Commit

Permalink
Make _timescaledb_functions.makeaclitem strict
Browse files Browse the repository at this point in the history
Function `_timescaledb_functions.makeaclitem` needs to be strict since
if it is called with NULL values, it should return NULL.
  • Loading branch information
mkindahl committed Nov 9, 2023
1 parent b423d14 commit 1071485
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions .unreleased/fix_6305
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #6305 Make _timescaledb_functions.makeaclitem strict
2 changes: 1 addition & 1 deletion sql/maintenance_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ $$ LANGUAGE plpgsql;
-- This is intended for internal usage and interface might change.
CREATE FUNCTION _timescaledb_functions.makeaclitem(regrole, regrole, text, bool)
RETURNS AclItem AS '@MODULE_PATHNAME@', 'ts_makeaclitem'
LANGUAGE C STABLE PARALLEL SAFE;
LANGUAGE C STABLE PARALLEL SAFE STRICT;

-- Repair relation ACL by removing roles that do not exist in pg_authid.
CREATE PROCEDURE _timescaledb_functions.repair_relation_acls()
Expand Down
14 changes: 14 additions & 0 deletions test/expected/util.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
\set ECHO errors
item
--------------------
wizard=a/wizard
wizard=ar/wizard
wizard=a*/wizard
wizard=a*r*/wizard
[NULL]
[NULL]
[NULL]
[NULL]
=a*r*/wizard
wizard=a*r*/0
(10 rows)

18 changes: 18 additions & 0 deletions test/sql/util.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@

\set ECHO errors
\set VERBOSITY default
\c :TEST_DBNAME :ROLE_SUPERUSER

DO $$
BEGIN
ASSERT( _timescaledb_functions.get_partition_for_key(''::text) = 669664877 );
ASSERT( _timescaledb_functions.get_partition_for_key('dev1'::text) = 1129986420 );
ASSERT( _timescaledb_functions.get_partition_for_key('longlonglonglongpartitionkey'::text) = 1169179734);
END$$;

\pset null '[NULL]'
CREATE USER wizard;
SELECT * FROM (
VALUES
(_timescaledb_functions.makeaclitem('wizard', 'wizard', 'insert', false)),
(_timescaledb_functions.makeaclitem('wizard', 'wizard', 'insert,select', false)),
(_timescaledb_functions.makeaclitem('wizard', 'wizard', 'insert', true)),
(_timescaledb_functions.makeaclitem('wizard', 'wizard', 'insert,select', true)),
(_timescaledb_functions.makeaclitem(NULL, 'wizard', 'insert,select', true)),
(_timescaledb_functions.makeaclitem('wizard', NULL, 'insert,select', true)),
(_timescaledb_functions.makeaclitem('wizard', 'wizard', NULL, true)),
(_timescaledb_functions.makeaclitem('wizard', 'wizard', 'insert,select', NULL)),
(_timescaledb_functions.makeaclitem(0, 'wizard', 'insert,select', true)),
(_timescaledb_functions.makeaclitem('wizard', 0, 'insert,select', true))
) AS t(item);
DROP USER wizard;

0 comments on commit 1071485

Please sign in to comment.