Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3125a5b

Browse files
committed
Fix possible future cache reference leak in ALTER EXTENSION ADD/DROP.
recordExtObjInitPriv and removeExtObjInitPriv were sloppy aboutcalling ReleaseSysCache. The cases cannot occur given current usagein ALTER EXTENSION ADD/DROP, since we wouldn't get here for theserelkinds; but it seems wise to clean up better.In passing, extend test logic in test_pg_dump to exercise thedropped-column code paths here.Since the case is unreachable at present, there seems no greatneed to back-patch; hence fix HEAD only.Kyotaro Horiguchi, with test case and comment adjustments by meDiscussion:https://postgr.es/m/20200417.151831.1153577605111650154.horikyota.ntt@gmail.com
1 parent4db819b commit3125a5b

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

‎src/backend/catalog/aclchk.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5580,19 +5580,22 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
55805580
elog(ERROR,"cache lookup failed for relation %u",objoid);
55815581
pg_class_tuple= (Form_pg_class)GETSTRUCT(tuple);
55825582

5583-
/* Indexes don't have permissions */
5583+
/*
5584+
* Indexes don't have permissions, neither do the pg_class rows for
5585+
* composite types. (These cases are unreachable given the
5586+
* restrictions in ALTER EXTENSION ADD, but let's check anyway.)
5587+
*/
55845588
if (pg_class_tuple->relkind==RELKIND_INDEX||
5585-
pg_class_tuple->relkind==RELKIND_PARTITIONED_INDEX)
5586-
return;
5587-
5588-
/* Composite types don't have permissions either */
5589-
if (pg_class_tuple->relkind==RELKIND_COMPOSITE_TYPE)
5589+
pg_class_tuple->relkind==RELKIND_PARTITIONED_INDEX||
5590+
pg_class_tuple->relkind==RELKIND_COMPOSITE_TYPE)
5591+
{
5592+
ReleaseSysCache(tuple);
55905593
return;
5594+
}
55915595

55925596
/*
5593-
* If this isn't a sequence, index, or composite type then it's
5594-
* possibly going to have columns associated with it that might have
5595-
* ACLs.
5597+
* If this isn't a sequence then it's possibly going to have
5598+
* column-level ACLs associated with it.
55965599
*/
55975600
if (pg_class_tuple->relkind!=RELKIND_SEQUENCE)
55985601
{
@@ -5724,6 +5727,11 @@ recordExtObjInitPriv(Oid objoid, Oid classoid)
57245727
SysScanDescscan;
57255728
Relationrelation;
57265729

5730+
/*
5731+
* Note: this is dead code, given that we don't allow large objects to
5732+
* be made extension members. But it seems worth carrying in case
5733+
* some future caller of this function has need for it.
5734+
*/
57275735
relation=table_open(LargeObjectMetadataRelationId,RowExclusiveLock);
57285736

57295737
/* There's no syscache for pg_largeobject_metadata */
@@ -5866,19 +5874,22 @@ removeExtObjInitPriv(Oid objoid, Oid classoid)
58665874
elog(ERROR,"cache lookup failed for relation %u",objoid);
58675875
pg_class_tuple= (Form_pg_class)GETSTRUCT(tuple);
58685876

5869-
/* Indexes don't have permissions */
5877+
/*
5878+
* Indexes don't have permissions, neither do the pg_class rows for
5879+
* composite types. (These cases are unreachable given the
5880+
* restrictions in ALTER EXTENSION DROP, but let's check anyway.)
5881+
*/
58705882
if (pg_class_tuple->relkind==RELKIND_INDEX||
5871-
pg_class_tuple->relkind==RELKIND_PARTITIONED_INDEX)
5872-
return;
5873-
5874-
/* Composite types don't have permissions either */
5875-
if (pg_class_tuple->relkind==RELKIND_COMPOSITE_TYPE)
5883+
pg_class_tuple->relkind==RELKIND_PARTITIONED_INDEX||
5884+
pg_class_tuple->relkind==RELKIND_COMPOSITE_TYPE)
5885+
{
5886+
ReleaseSysCache(tuple);
58765887
return;
5888+
}
58775889

58785890
/*
5879-
* If this isn't a sequence, index, or composite type then it's
5880-
* possibly going to have columns associated with it that might have
5881-
* ACLs.
5891+
* If this isn't a sequence then it's possibly going to have
5892+
* column-level ACLs associated with it.
58825893
*/
58835894
if (pg_class_tuple->relkind!=RELKIND_SEQUENCE)
58845895
{

‎src/test/modules/test_pg_dump/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
test_pg_dump is an extension explicitly to test pg_dump when
22
extensions are present in the system.
3+
4+
We also make use of this module to test ALTER EXTENSION ADD/DROP.

‎src/test/modules/test_pg_dump/expected/test_pg_dump.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ ALTER EXTENSION test_pg_dump ADD DATABASE postgres; -- error
44
ERROR: syntax error at or near "DATABASE"
55
LINE 1: ALTER EXTENSION test_pg_dump ADD DATABASE postgres;
66
^
7-
CREATE TABLE test_pg_dump_t1 (c1 int);
7+
CREATE TABLE test_pg_dump_t1 (c1 int, junk text);
8+
ALTER TABLE test_pg_dump_t1 DROP COLUMN junk; -- to exercise dropped-col cases
89
CREATE VIEW test_pg_dump_v1 AS SELECT * FROM test_pg_dump_t1;
910
CREATE MATERIALIZED VIEW test_pg_dump_mv1 AS SELECT * FROM test_pg_dump_t1;
1011
CREATE SCHEMA test_pg_dump_s1;

‎src/test/modules/test_pg_dump/sql/test_pg_dump.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ CREATE EXTENSION test_pg_dump;
33

44
ALTER EXTENSION test_pg_dump ADD DATABASE postgres;-- error
55

6-
CREATETABLEtest_pg_dump_t1 (c1int);
6+
CREATETABLEtest_pg_dump_t1 (c1int, junktext);
7+
ALTERTABLE test_pg_dump_t1 DROP COLUMN junk;-- to exercise dropped-col cases
78
CREATEVIEWtest_pg_dump_v1ASSELECT*FROM test_pg_dump_t1;
89
CREATE MATERIALIZED VIEW test_pg_dump_mv1ASSELECT*FROM test_pg_dump_t1;
910
CREATESCHEMAtest_pg_dump_s1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp