Fix use-after-free bug when renaming constraints
authorMichael Paquier
Mon, 17 Dec 2018 03:43:48 +0000 (12:43 +0900)
committerMichael Paquier
Mon, 17 Dec 2018 03:43:48 +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 8893522e1d01b0098134643dbd6a9c938a5dd090..04795a33a4346454ed57274cc1da632848c3cb08 100644 (file)
@@ -2828,12 +2828,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 37ba3876dca2b9a3c330279277ca5bcfe4235bec..20f7d926b29e94d360cd296afa1d225010d540f6 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 56033ae631b425be15ff3c7aaec1f136c87158bd..ea94eb8f162a966430642449145521e7387b55f8 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