Skip to content

Commit 696c68c

Browse files
committed
Fix use-after-free bug when renaming constraints
This is an oversight from recent commit b13fd34. 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.
1 parent d5d86e2 commit 696c68c

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,12 +2429,12 @@ rename_constraint_internal(Oid myrelid,
24292429

24302430
if (targetrelation)
24312431
{
2432-
relation_close(targetrelation, NoLock); /* close rel but keep lock */
2433-
24342432
/*
24352433
* Invalidate relcache so as others can see the new constraint name.
24362434
*/
24372435
CacheInvalidateRelcache(targetrelation);
2436+
2437+
relation_close(targetrelation, NoLock); /* close rel but keep lock */
24382438
}
24392439

24402440
return constraintOid;

src/test/regress/expected/alter_table.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ CREATE TABLE constraint_rename_cache (a int,
347347
ALTER TABLE constraint_rename_cache
348348
RENAME CONSTRAINT chk_a TO chk_a_new;
349349
ALTER TABLE constraint_rename_cache
350-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
350+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
351351
CREATE TABLE like_constraint_rename_cache
352352
(LIKE constraint_rename_cache INCLUDING ALL);
353353
\d like_constraint_rename_cache

src/test/regress/sql/alter_table.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ CREATE TABLE constraint_rename_cache (a int,
257257
ALTER TABLE constraint_rename_cache
258258
RENAME CONSTRAINT chk_a TO chk_a_new;
259259
ALTER TABLE constraint_rename_cache
260-
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
260+
RENAME CONSTRAINT constraint_rename_cache_pkey TO constraint_rename_pkey_new;
261261
CREATE TABLE like_constraint_rename_cache
262262
(LIKE constraint_rename_cache INCLUDING ALL);
263263
\d like_constraint_rename_cache

0 commit comments

Comments
 (0)