diff options
author | Robert Haas <rhaas@postgresql.org> | 2014-02-17 09:33:31 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2014-02-17 09:33:31 -0500 |
commit | 5f173040e324f6c2eebb90d86cf1b0cdb5890f0a (patch) | |
tree | 9c3d313acb74c092bc2664b862720f340460bb80 /src/backend/catalog/pg_constraint.c | |
parent | 540b4e5bc85f7e44842493a810b04a84881db20f (diff) | |
download | postgresql-5f173040e324f6c2eebb90d86cf1b0cdb5890f0a.tar.gz postgresql-5f173040e324f6c2eebb90d86cf1b0cdb5890f0a.zip |
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
Diffstat (limited to 'src/backend/catalog/pg_constraint.c')
-rw-r--r-- | src/backend/catalog/pg_constraint.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c index f2209c82103..5fd9822c6ed 100644 --- a/src/backend/catalog/pg_constraint.c +++ b/src/backend/catalog/pg_constraint.c @@ -752,6 +752,25 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, } /* + * get_constraint_relation_oids + * Find the IDs of the relations to which a constraint refers. + */ +void +get_constraint_relation_oids(Oid constraint_oid, Oid *conrelid, Oid *confrelid) +{ + HeapTuple tup; + Form_pg_constraint con; + + tup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constraint_oid)); + if (!HeapTupleIsValid(tup)) /* should not happen */ + elog(ERROR, "cache lookup failed for constraint %u", constraint_oid); + con = (Form_pg_constraint) GETSTRUCT(tup); + *conrelid = con->conrelid; + *confrelid = con->confrelid; + ReleaseSysCache(tup); +} + +/* * get_relation_constraint_oid * Find a constraint on the specified relation with the specified name. * Returns constraint's OID. |