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

Commitcc2737a

Browse files
committed
Fix cache reference leak in contrib/sepgsql.
fixup_whole_row_references() did the wrong thing with a dropped column,resulting in a commit-time warning about a cache reference leak.I (tgl) added a test case exercising this, but back-patched the testonly as far as v10; the patch didn't apply cleanly to 9.6 and itdidn't seem worth the trouble to adapt it. The bug is pretty oldthough, so apply the code change all the way back.Michael Luo, with cosmetic improvements by meDiscussion:https://postgr.es/m/BYAPR08MB5606D1453D7F50E2AF4D2FD29AD80@BYAPR08MB5606.namprd08.prod.outlook.com
1 parent7347855 commitcc2737a

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

‎contrib/sepgsql/dml.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
/*
3232
* fixup_whole_row_references
3333
*
34-
* When userreference a whole ofrow, it is equivalent toreference to
34+
* When userreferences a whole-row Var, it is equivalent toreferencing
3535
* all the user columns (not system columns). So, we need to fix up the
36-
* given bitmapset, if it contains a whole of therow reference.
36+
* given bitmapset, if it contains a whole-row reference.
3737
*/
3838
staticBitmapset*
3939
fixup_whole_row_references(OidrelOid,Bitmapset*columns)
@@ -44,7 +44,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
4444
AttrNumberattno;
4545
intindex;
4646

47-
/* if no whole ofrow references,do not anything */
47+
/* if no whole-row references,nothing to do */
4848
index=InvalidAttrNumber-FirstLowInvalidHeapAttributeNumber;
4949
if (!bms_is_member(index,columns))
5050
returncolumns;
@@ -56,7 +56,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
5656
natts= ((Form_pg_class)GETSTRUCT(tuple))->relnatts;
5757
ReleaseSysCache(tuple);
5858

59-
/*fix upthegiven columns */
59+
/*remove bit 0 from column set, add in allthenon-dropped columns */
6060
result=bms_copy(columns);
6161
result=bms_del_member(result,index);
6262

@@ -66,14 +66,13 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
6666
ObjectIdGetDatum(relOid),
6767
Int16GetDatum(attno));
6868
if (!HeapTupleIsValid(tuple))
69-
continue;
70-
71-
if (((Form_pg_attribute)GETSTRUCT(tuple))->attisdropped)
72-
continue;
73-
74-
index=attno-FirstLowInvalidHeapAttributeNumber;
69+
continue;/* unexpected case, should we error? */
7570

76-
result=bms_add_member(result,index);
71+
if (!((Form_pg_attribute)GETSTRUCT(tuple))->attisdropped)
72+
{
73+
index=attno-FirstLowInvalidHeapAttributeNumber;
74+
result=bms_add_member(result,index);
75+
}
7776

7877
ReleaseSysCache(tuple);
7978
}

‎contrib/sepgsql/expected/dml.out

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
--
55
-- Setup
66
--
7-
CREATE TABLE t1 (a int, b text);
7+
CREATE TABLE t1 (a int,junk int,b text);
88
SECURITY LABEL ON TABLE t1 IS 'system_u:object_r:sepgsql_table_t:s0';
9+
ALTER TABLE t1 DROP COLUMN junk;
910
INSERT INTO t1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc');
1011
CREATE TABLE t2 (x int, y text);
1112
SECURITY LABEL ON TABLE t2 IS 'system_u:object_r:sepgsql_ro_table_t:s0';
1213
INSERT INTO t2 VALUES (1, 'xxx'), (2, 'yyy'), (3, 'zzz');
1314
CREATE TABLE t3 (s int, t text);
1415
SECURITY LABEL ON TABLE t3 IS 'system_u:object_r:sepgsql_fixed_table_t:s0';
1516
INSERT INTO t3 VALUES (1, 'sss'), (2, 'ttt'), (3, 'uuu');
16-
CREATE TABLE t4 (m int, n text);
17+
CREATE TABLE t4 (m int,junk int,n text);
1718
SECURITY LABEL ON TABLE t4 IS 'system_u:object_r:sepgsql_secret_table_t:s0';
19+
ALTER TABLE t4 DROP COLUMN junk;
1820
INSERT INTO t4 VALUES (1, 'mmm'), (2, 'nnn'), (3, 'ooo');
1921
CREATE TABLE t5 (e text, f text, g text);
2022
SECURITY LABEL ON TABLE t5 IS 'system_u:object_r:sepgsql_table_t:s0';
@@ -136,6 +138,16 @@ SELECT e,f FROM t5;-- ok
136138
---+---
137139
(0 rows)
138140

141+
SELECT (t1.*)::record FROM t1;-- ok
142+
t1
143+
---------
144+
(1,aaa)
145+
(2,bbb)
146+
(3,ccc)
147+
(3 rows)
148+
149+
SELECT (t4.*)::record FROM t4;-- failed
150+
ERROR: SELinux: security policy violation
139151
---
140152
-- partitioned table parent
141153
SELECT * FROM t1p;-- failed

‎contrib/sepgsql/sql/dml.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
--
66
-- Setup
77
--
8-
CREATETABLEt1 (aint, btext);
8+
CREATETABLEt1 (aint,junkint,btext);
99
SECURITY LABELON TABLE t1 IS'system_u:object_r:sepgsql_table_t:s0';
10+
ALTERTABLE t1 DROP COLUMN junk;
1011
INSERT INTO t1VALUES (1,'aaa'), (2,'bbb'), (3,'ccc');
1112

1213
CREATETABLEt2 (xint, ytext);
@@ -17,8 +18,9 @@ CREATE TABLE t3 (s int, t text);
1718
SECURITY LABELON TABLE t3 IS'system_u:object_r:sepgsql_fixed_table_t:s0';
1819
INSERT INTO t3VALUES (1,'sss'), (2,'ttt'), (3,'uuu');
1920

20-
CREATETABLEt4 (mint, ntext);
21+
CREATETABLEt4 (mint,junkint,ntext);
2122
SECURITY LABELON TABLE t4 IS'system_u:object_r:sepgsql_secret_table_t:s0';
23+
ALTERTABLE t4 DROP COLUMN junk;
2224
INSERT INTO t4VALUES (1,'mmm'), (2,'nnn'), (3,'ooo');
2325

2426
CREATETABLEt5 (etext, ftext, gtext);
@@ -95,6 +97,8 @@ SELECT * FROM t3;-- ok
9597
SELECT*FROM t4;-- failed
9698
SELECT*FROM t5;-- failed
9799
SELECT e,fFROM t5;-- ok
100+
SELECT (t1.*)::recordFROM t1;-- ok
101+
SELECT (t4.*)::recordFROM t4;-- failed
98102

99103
---
100104
-- partitioned table parent

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp