]> granicus.if.org Git - postgresql/commitdiff
Fix use-after-free bug when renaming constraints
authorMichael Paquier <michael@paquier.xyz>
Mon, 17 Dec 2018 03:43:57 +0000 (12:43 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 17 Dec 2018 03:43:57 +0000 (12:43 +0900)
This is an oversight from recent commit b13fd344.  While on it, tweak
the previous test with a better name for the renamed primary key.

Detected by buildfarm member prion which forces relation cache release
with -DRELCACHE_FORCE_RELEASE.  Back-patch down to 9.4 as the previous
commit.

src/backend/commands/tablecmds.c
src/test/regress/expected/alter_table.out
src/test/regress/sql/alter_table.sql

index 0747f90c3414f84f2b5c3c7d49b386cbba849c45..7a30da5d0db4c51957c12e1619e7250e923e2ffe 100644 (file)
@@ -2495,12 +2495,12 @@ rename_constraint_internal(Oid myrelid,
 
        if (targetrelation)
        {
-               relation_close(targetrelation, NoLock); /* close rel but keep lock */
-
                /*
                 * Invalidate relcache so as others can see the new constraint name.
                 */
                CacheInvalidateRelcache(targetrelation);
+
+               relation_close(targetrelation, NoLock); /* close rel but keep lock */
        }
 
        return address;
index b860caadf636b77f469e084e5d6fc3651b166971..b5c4e82410c2caf21559b9b1e5eb71e12ad4d5be 100644 (file)
@@ -349,7 +349,7 @@ CREATE TABLE constraint_rename_cache (a int,
 ALTER TABLE constraint_rename_cache
   RENAME CONSTRAINT chk_a TO chk_a_new;
 ALTER TABLE constraint_rename_cache
-  RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
+  RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
 CREATE TABLE like_constraint_rename_cache
   (LIKE constraint_rename_cache INCLUDING ALL);
 \d like_constraint_rename_cache
index 522e96c01191b670fc25d011dccb1f8f915a9767..fdc300d6b721b1b7e7829ec018c6e76e5dfddd8b 100644 (file)
@@ -258,7 +258,7 @@ CREATE TABLE constraint_rename_cache (a int,
 ALTER TABLE constraint_rename_cache
   RENAME CONSTRAINT chk_a TO chk_a_new;
 ALTER TABLE constraint_rename_cache
-  RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
+  RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
 CREATE TABLE like_constraint_rename_cache
   (LIKE constraint_rename_cache INCLUDING ALL);
 \d like_constraint_rename_cache