]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix lookup error in extended stats ownership check
authorTomas Vondra <tomas.vondra@postgresql.org>
Tue, 31 Aug 2021 16:03:05 +0000 (18:03 +0200)
committerTomas Vondra <tomas.vondra@postgresql.org>
Tue, 31 Aug 2021 16:38:11 +0000 (18:38 +0200)
When an ownership check on extended statistics object failed, the code
was calling aclcheck_error_type to report the failure, which is clearly
wrong, resulting in cache lookup errors. Fix by calling aclcheck_error.

This issue exists since the introduction of extended statistics, so
backpatch all the way back to PostgreSQL 10. It went unnoticed because
there were no tests triggering the error, so add one.

Reported-by: Mark Dilger
Backpatch-through: 10, where extended stats were introduced
Discussion: https://postgr.es/m/1F238937-7CC2-4703-A1B1-6DC225B8978A%40enterprisedb.com

src/backend/catalog/objectaddress.c
src/test/regress/expected/stats_ext.out
src/test/regress/sql/stats_ext.sql

index 64ceccbf004e4c9584d13137dab05ff2277c18da..91c722adf628cccded072a923c76a7012b7e7008 100644 (file)
@@ -2476,7 +2476,8 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
                        break;
                case OBJECT_STATISTIC_EXT:
                        if (!pg_statistics_object_ownercheck(address.objectId, roleid))
-                               aclcheck_error_type(ACLCHECK_NOT_OWNER, address.objectId);
+                               aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
+                                                          NameListToString(castNode(List, object)));
                        break;
                default:
                        elog(ERROR, "unrecognized object type: %d",
index 7524e651422dadd872105dc3832a5765549c43d3..7f8c642a185ad8e89a6c0aa6c7c520f123627185 100644 (file)
@@ -54,6 +54,17 @@ DROP TABLE ext_stats_test;
 -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
 CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
 CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
+COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
+CREATE ROLE temp_role;
+SET SESSION AUTHORIZATION temp_role;
+COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
+ERROR:  must be owner of statistics object ab1_a_b_stats
+DROP STATISTICS ab1_a_b_stats;
+ERROR:  must be owner of statistics object ab1_a_b_stats
+ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
+ERROR:  must be owner of statistics object ab1_a_b_stats
+RESET SESSION AUTHORIZATION;
+DROP ROLE temp_role;
 CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
 NOTICE:  statistics object "ab1_a_b_stats" already exists, skipping
 DROP STATISTICS ab1_a_b_stats;
index 906503bd0bc041bee5a6bce96fb9b0ef76073452..03881a302d1ac275177d7f6da0188b28ac3a3aae 100644 (file)
@@ -43,6 +43,15 @@ DROP TABLE ext_stats_test;
 -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
 CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
 CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
+COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
+CREATE ROLE temp_role;
+SET SESSION AUTHORIZATION temp_role;
+COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
+DROP STATISTICS ab1_a_b_stats;
+ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
+RESET SESSION AUTHORIZATION;
+DROP ROLE temp_role;
+
 CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
 DROP STATISTICS ab1_a_b_stats;