Fix use-after-free bug when renaming constraints
authorMichael Paquier
Mon, 17 Dec 2018 03:44:09 +0000 (12:44 +0900)
committerMichael Paquier
Mon, 17 Dec 2018 03:44:09 +0000 (12:44 +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 8c2f650a88a977f0f136c81e8e2762f0e9d9f96c..49a53816a651ea6e9fab700b465d4c12dc0ec266 100644 (file)
@@ -2429,12 +2429,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 constraintOid;
index bd63075139c7dddf57facffb5a9374e434323199..1a55bf71847391c2be3e0faf8d9a5a2a99cf2544 100644 (file)
@@ -347,7 +347,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 4ccba34409e47a15c36902c8252a47e5043a6dfa..03a3789f3ff08d18eaf981bfb75673a01b7e71d7 100644 (file)
@@ -257,7 +257,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