fix_pg_dump_proof_of_concept.patch
text/x-diff
Filename: fix_pg_dump_proof_of_concept.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| contrib/pg_trgm/expected/pg_trgm.out | 15 | 0 |
| contrib/pg_trgm/sql/pg_trgm.sql | 11 | 0 |
| src/backend/commands/indexcmds.c | 20 | 4 |
diff --git a/contrib/pg_trgm/expected/pg_trgm.out b/contrib/pg_trgm/expected/pg_trgm.out
index 20141ce7f3..060fd8e23d 100644
--- a/contrib/pg_trgm/expected/pg_trgm.out
+++ b/contrib/pg_trgm/expected/pg_trgm.out
@@ -5402,3 +5402,18 @@ SELECT DISTINCT city, similarity(city, 'Warsaw'), show_limit()
Warsaw | 1 | 0.5
(1 row)
+DROP EXTENSION pg_trgm CASCADE;
+NOTICE: drop cascades to 4 other objects
+DETAIL: drop cascades to index test2_idx_gist
+drop cascades to index restaurants_city_idx
+drop cascades to index trgm_idx
+drop cascades to index t_trgm_idx
+BEGIN;
+CREATE ROLE limitedrole;
+CREATE SCHEMA ext_trgm;
+CREATE EXTENSION pg_trgm SCHEMA ext_trgm;
+CREATE TABLE x(y text);
+ALTER TABLE x OWNER TO limitedrole;
+CREATE INDEX ON x USING gist(y ext_trgm.gist_trgm_ops);
+ROLLBACK;
+CREATE EXTENSION pg_trgm;
diff --git a/contrib/pg_trgm/sql/pg_trgm.sql b/contrib/pg_trgm/sql/pg_trgm.sql
index 6a9da24d5a..00917f8085 100644
--- a/contrib/pg_trgm/sql/pg_trgm.sql
+++ b/contrib/pg_trgm/sql/pg_trgm.sql
@@ -236,3 +236,14 @@ SELECT DISTINCT city, similarity(city, 'Warsaw'), show_limit()
SELECT set_limit(0.5);
SELECT DISTINCT city, similarity(city, 'Warsaw'), show_limit()
FROM restaurants WHERE city % 'Warsaw';
+
+DROP EXTENSION pg_trgm CASCADE;
+BEGIN;
+CREATE ROLE limitedrole;
+CREATE SCHEMA ext_trgm;
+CREATE EXTENSION pg_trgm SCHEMA ext_trgm;
+CREATE TABLE x(y text);
+ALTER TABLE x OWNER TO limitedrole;
+CREATE INDEX ON x USING gist(y ext_trgm.gist_trgm_ops);
+ROLLBACK;
+CREATE EXTENSION pg_trgm;
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index eac13ac0b7..d4c718b696 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -80,7 +80,9 @@ static void ComputeIndexAttrs(IndexInfo *indexInfo,
Oid relId,
const char *accessMethodName, Oid accessMethodId,
bool amcanorder,
- bool isconstraint);
+ bool isconstraint,
+ Oid root_save_userid,
+ int root_save_sec_context);
static char *ChooseIndexName(const char *tabname, Oid namespaceId,
List *colnames, List *exclusionOpNames,
bool primary, bool isconstraint);
@@ -236,7 +238,7 @@ CheckIndexCompatible(Oid oldId,
coloptions, attributeList,
exclusionOpNames, relationId,
accessMethodName, accessMethodId,
- amcanorder, isconstraint);
+ amcanorder, isconstraint, 0, 0);
/* Get the soon-obsolete pg_index tuple. */
@@ -890,7 +892,8 @@ DefineIndex(Oid relationId,
coloptions, allIndexParams,
stmt->excludeOpNames, relationId,
accessMethodName, accessMethodId,
- amcanorder, stmt->isconstraint);
+ amcanorder, stmt->isconstraint, root_save_userid,
+ root_save_sec_context);
/*
* Extra checks when creating a PRIMARY KEY index.
@@ -1743,12 +1746,16 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
const char *accessMethodName,
Oid accessMethodId,
bool amcanorder,
- bool isconstraint)
+ bool isconstraint,
+ Oid root_save_userid,
+ int root_save_sec_context)
{
ListCell *nextExclOp;
ListCell *lc;
int attn;
int nkeycols = indexInfo->ii_NumIndexKeyAttrs;
+ Oid saved_userid;
+ int saved_sec_ctx;
/* Allocate space for exclusion operator info, if needed */
if (exclusionOpNames)
@@ -1922,6 +1929,12 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
collationOidP[attn] = attcollation;
+ if (OidIsValid(root_save_userid))
+ {
+ GetUserIdAndSecContext(&saved_userid, &saved_sec_ctx);
+ SetUserIdAndSecContext(root_save_userid, root_save_sec_context);
+ }
+
/*
* Identify the opclass to use.
*/
@@ -1930,6 +1943,9 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
accessMethodName,
accessMethodId);
+ if (OidIsValid(root_save_userid))
+ SetUserIdAndSecContext(saved_userid, saved_sec_ctx);
+
/*
* Identify the exclusion operator, if any.
*/