Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitceac450

Browse files
committed
Fix handling of COMMENT for domain constraints
For a non-superuser, changing a comment on a domain constraint wasleading to a cache lookup failure as the code tried to perform theownership lookup on the constraint OID itself, thinking that it was atype, but this check needs to happen on the type the domain constraintrelies on. As the type a domain constraint relies on can be guesseddirectly based on the constraint OID, first fetch its type OID andperform the ownership on it.This is broken since7eca575, which has split the handling of commentsfor table constraints and domain constraints, so back-patch down to9.5.Reported-by: Clemens LadischAuthor: Daniel Gustafsson, Michael PaquierReviewed-by: Álvaro HerreraDiscussion:https://postgr.es/m/15833-808e11904835d26f@postgresql.orgBackpatch-through: 9.5
1 parente788e84 commitceac450

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,10 +2295,32 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
22952295
caseOBJECT_TYPE:
22962296
caseOBJECT_DOMAIN:
22972297
caseOBJECT_ATTRIBUTE:
2298-
caseOBJECT_DOMCONSTRAINT:
22992298
if (!pg_type_ownercheck(address.objectId,roleid))
23002299
aclcheck_error_type(ACLCHECK_NOT_OWNER,address.objectId);
23012300
break;
2301+
caseOBJECT_DOMCONSTRAINT:
2302+
{
2303+
HeapTupletuple;
2304+
Oidcontypid;
2305+
2306+
tuple=SearchSysCache1(CONSTROID,
2307+
ObjectIdGetDatum(address.objectId));
2308+
if (!HeapTupleIsValid(tuple))
2309+
elog(ERROR,"constraint with OID %u does not exist",
2310+
address.objectId);
2311+
2312+
contypid= ((Form_pg_constraint)GETSTRUCT(tuple))->contypid;
2313+
2314+
ReleaseSysCache(tuple);
2315+
2316+
/*
2317+
* Fallback to type ownership check in this case as this is
2318+
* what domain constraints rely on.
2319+
*/
2320+
if (!pg_type_ownercheck(contypid,roleid))
2321+
aclcheck_error_type(ACLCHECK_NOT_OWNER,contypid);
2322+
}
2323+
break;
23022324
caseOBJECT_AGGREGATE:
23032325
caseOBJECT_FUNCTION:
23042326
caseOBJECT_PROCEDURE:

‎src/test/regress/input/constraints.source

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ ALTER TABLE deferred_excl ADD EXCLUDE (f1 WITH =);
518518
DROP TABLE deferred_excl;
519519

520520
-- Comments
521+
-- Setup a low-level role to enforce non-superuser checks.
522+
CREATE ROLE regress_constraint_comments;
523+
SET SESSION AUTHORIZATION regress_constraint_comments;
524+
521525
CREATE TABLE constraint_comments_tbl (a int CONSTRAINT the_constraint CHECK (a > 0));
522526
CREATE DOMAIN constraint_comments_dom AS int CONSTRAINT the_constraint CHECK (value > 0);
523527

@@ -535,5 +539,16 @@ COMMENT ON CONSTRAINT the_constraint ON DOMAIN no_comments_dom IS 'another bad c
535539
COMMENT ON CONSTRAINT the_constraint ON constraint_comments_tbl IS NULL;
536540
COMMENT ON CONSTRAINT the_constraint ON DOMAIN constraint_comments_dom IS NULL;
537541

542+
-- unauthorized user
543+
RESET SESSION AUTHORIZATION;
544+
CREATE ROLE regress_constraint_comments_noaccess;
545+
SET SESSION AUTHORIZATION regress_constraint_comments_noaccess;
546+
COMMENT ON CONSTRAINT the_constraint ON constraint_comments_tbl IS 'no, the comment';
547+
COMMENT ON CONSTRAINT the_constraint ON DOMAIN constraint_comments_dom IS 'no, another comment';
548+
RESET SESSION AUTHORIZATION;
549+
538550
DROP TABLE constraint_comments_tbl;
539551
DROP DOMAIN constraint_comments_dom;
552+
553+
DROP ROLE regress_constraint_comments;
554+
DROP ROLE regress_constraint_comments_noaccess;

‎src/test/regress/output/constraints.source

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,9 @@ ERROR: could not create exclusion constraint "deferred_excl_f1_excl"
704704
DETAIL: Key (f1)=(3) conflicts with key (f1)=(3).
705705
DROP TABLE deferred_excl;
706706
-- Comments
707+
-- Setup a low-level role to enforce non-superuser checks.
708+
CREATE ROLE regress_constraint_comments;
709+
SET SESSION AUTHORIZATION regress_constraint_comments;
707710
CREATE TABLE constraint_comments_tbl (a int CONSTRAINT the_constraint CHECK (a > 0));
708711
CREATE DOMAIN constraint_comments_dom AS int CONSTRAINT the_constraint CHECK (value > 0);
709712
COMMENT ON CONSTRAINT the_constraint ON constraint_comments_tbl IS 'yes, the comment';
@@ -720,5 +723,16 @@ COMMENT ON CONSTRAINT the_constraint ON DOMAIN no_comments_dom IS 'another bad c
720723
ERROR: type "no_comments_dom" does not exist
721724
COMMENT ON CONSTRAINT the_constraint ON constraint_comments_tbl IS NULL;
722725
COMMENT ON CONSTRAINT the_constraint ON DOMAIN constraint_comments_dom IS NULL;
726+
-- unauthorized user
727+
RESET SESSION AUTHORIZATION;
728+
CREATE ROLE regress_constraint_comments_noaccess;
729+
SET SESSION AUTHORIZATION regress_constraint_comments_noaccess;
730+
COMMENT ON CONSTRAINT the_constraint ON constraint_comments_tbl IS 'no, the comment';
731+
ERROR: must be owner of relation constraint_comments_tbl
732+
COMMENT ON CONSTRAINT the_constraint ON DOMAIN constraint_comments_dom IS 'no, another comment';
733+
ERROR: must be owner of type constraint_comments_dom
734+
RESET SESSION AUTHORIZATION;
723735
DROP TABLE constraint_comments_tbl;
724736
DROP DOMAIN constraint_comments_dom;
737+
DROP ROLE regress_constraint_comments;
738+
DROP ROLE regress_constraint_comments_noaccess;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp