aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-07-10 09:40:22 +0900
committerMichael Paquier <michael@paquier.xyz>2023-07-10 09:40:22 +0900
commit02021f1b2f65fb86b7f8581f90dd8575fd39daf4 (patch)
tree614bd05032941457144b3eecb485534f5da36abe
parent9f236198c31de5340bd2227438b239a465c6eab3 (diff)
downloadpostgresql-02021f1b2f65fb86b7f8581f90dd8575fd39daf4.tar.gz
postgresql-02021f1b2f65fb86b7f8581f90dd8575fd39daf4.zip
Fix ALTER EXTENSION SET SCHEMA with objects outside an extension's schema
As coded, the code would use as a base comparison the namespace OID from the first object scanned in pg_depend when switching its namespace dependency entry to the new one, and use it as a base of comparison for any follow-up checks. It would also be used as the old namespace OID to switch *from* for the extension's pg_depend entry. Hence, if the first object scanned has a namespace different than the one stored in the extension, we would finish by: - Not checking that the extension objects map with the extension's schema. - Not switching the extension -> namespace dependency entry to the new namespace provided by the user, making ALTER EXTENSION ineffective. This issue exists since this command has been introduced in d9572c4 for relocatable extension, so backpatch all the way down to 11. The test case has been provided by Heikki, that I have tweaked a bit to show the effects on pg_depend for the extension. Reported-by: Heikki Linnakangas Author: Michael Paquier, Heikki Linnakangas Discussion: https://postgr.es/m/20eea594-a05b-4c31-491b-007b6fceef28@iki.fi Backpatch-through: 11
-rw-r--r--src/backend/commands/extension.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index f3f44b7f6de..7e81d848190 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -2706,7 +2706,7 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
{
Oid extensionOid;
Oid nspOid;
- Oid oldNspOid = InvalidOid;
+ Oid oldNspOid;
AclResult aclresult;
Relation extRel;
ScanKeyData key[2];
@@ -2789,6 +2789,9 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
objsMoved = new_object_addresses();
+ /* store the OID of the namespace to-be-changed */
+ oldNspOid = extForm->extnamespace;
+
/*
* Scan pg_depend to find objects that depend directly on the extension,
* and alter each one's schema.
@@ -2835,12 +2838,6 @@ AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *o
objsMoved);
/*
- * Remember previous namespace of first object that has one
- */
- if (oldNspOid == InvalidOid && dep_oldNspOid != InvalidOid)
- oldNspOid = dep_oldNspOid;
-
- /*
* If not all the objects had the same old namespace (ignoring any
* that are not in namespaces), complain.
*/