pgsql: Fix ALTER EXTENSION SET SCHEMA with objects outside an extension

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix ALTER EXTENSION SET SCHEMA with objects outside an extension
Date: 2023-07-10 00:42:44
Message-ID: E1qIezF-002knN-4c@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/55c95f24cd7c91fc80d7c0d2c842c0b633f9bdc9

Modified Files
--------------
src/backend/commands/extension.c | 11 ++----
.../test_extensions/expected/test_extensions.out | 43 ++++++++++++++++++++++
.../test_extensions/sql/test_extensions.sql | 32 ++++++++++++++++
3 files changed, 79 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2023-07-10 00:42:45 pgsql: Fix ALTER EXTENSION SET SCHEMA with objects outside an extension
Previous Message Peter Eisentraut 2023-07-09 08:03:48 pgsql: doc: Use proper markup for emphasis