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

Commitc029a6a

Browse files
committed
Fix contrib/pgstattuple and contrib/pageinspect to prevent attempts to read
temporary tables of other sessions; that is unsafe because of the way ourbuffer management works. Per report from Stuart Bishop.This is redundant with the bufmgr.c checks in HEAD, but not at all redundantin the back branches.
1 parent572b60a commitc029a6a

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

‎contrib/pageinspect/btreefuncs.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pageinspect/btreefuncs.c,v 1.8 2008/05/17 01:28:19 adunstan Exp $
2+
* $PostgreSQL: pgsql/contrib/pageinspect/btreefuncs.c,v 1.9 2009/03/31 22:54:31 tgl Exp $
33
*
44
*
55
* btreefuncs.c
@@ -190,6 +190,16 @@ bt_page_stats(PG_FUNCTION_ARGS)
190190
elog(ERROR,"relation \"%s\" is not a btree index",
191191
RelationGetRelationName(rel));
192192

193+
/*
194+
* Reject attempts to read non-local temporary relations; we would
195+
* be likely to get wrong data since we have no visibility into the
196+
* owning session's local buffers.
197+
*/
198+
if (RELATION_IS_OTHER_TEMP(rel))
199+
ereport(ERROR,
200+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
201+
errmsg("cannot access temporary tables of other sessions")));
202+
193203
if (blkno==0)
194204
elog(ERROR,"block 0 is a meta page");
195205

@@ -298,6 +308,16 @@ bt_page_items(PG_FUNCTION_ARGS)
298308
elog(ERROR,"relation \"%s\" is not a btree index",
299309
RelationGetRelationName(rel));
300310

311+
/*
312+
* Reject attempts to read non-local temporary relations; we would
313+
* be likely to get wrong data since we have no visibility into the
314+
* owning session's local buffers.
315+
*/
316+
if (RELATION_IS_OTHER_TEMP(rel))
317+
ereport(ERROR,
318+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
319+
errmsg("cannot access temporary tables of other sessions")));
320+
301321
if (blkno==0)
302322
elog(ERROR,"block 0 is a meta page");
303323

@@ -437,6 +457,16 @@ bt_metap(PG_FUNCTION_ARGS)
437457
elog(ERROR,"relation \"%s\" is not a btree index",
438458
RelationGetRelationName(rel));
439459

460+
/*
461+
* Reject attempts to read non-local temporary relations; we would
462+
* be likely to get wrong data since we have no visibility into the
463+
* owning session's local buffers.
464+
*/
465+
if (RELATION_IS_OTHER_TEMP(rel))
466+
ereport(ERROR,
467+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
468+
errmsg("cannot access temporary tables of other sessions")));
469+
440470
buffer=ReadBuffer(rel,0);
441471
page=BufferGetPage(buffer);
442472
metad=BTPageGetMeta(page);

‎contrib/pageinspect/rawpage.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Copyright (c) 2007-2009, PostgreSQL Global Development Group
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.10 2009/01/01 17:23:32 momjian Exp $
11+
* $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.11 2009/03/31 22:54:31 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -74,6 +74,16 @@ get_raw_page(PG_FUNCTION_ARGS)
7474
errmsg("cannot get raw page from composite type \"%s\"",
7575
RelationGetRelationName(rel))));
7676

77+
/*
78+
* Reject attempts to read non-local temporary relations; we would
79+
* be likely to get wrong data since we have no visibility into the
80+
* owning session's local buffers.
81+
*/
82+
if (RELATION_IS_OTHER_TEMP(rel))
83+
ereport(ERROR,
84+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
85+
errmsg("cannot access temporary tables of other sessions")));
86+
7787
if (blkno >=RelationGetNumberOfBlocks(rel))
7888
elog(ERROR,"block number %u is out of range for relation \"%s\"",
7989
blkno,RelationGetRelationName(rel));

‎contrib/pgstattuple/pgstatindex.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstatindex.c,v 1.11 2008/05/17 01:28:22 adunstan Exp $
2+
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstatindex.c,v 1.12 2009/03/31 22:54:31 tgl Exp $
33
*
44
*
55
* pgstatindex
@@ -107,6 +107,16 @@ pgstatindex(PG_FUNCTION_ARGS)
107107
elog(ERROR,"relation \"%s\" is not a btree index",
108108
RelationGetRelationName(rel));
109109

110+
/*
111+
* Reject attempts to read non-local temporary relations; we would
112+
* be likely to get wrong data since we have no visibility into the
113+
* owning session's local buffers.
114+
*/
115+
if (RELATION_IS_OTHER_TEMP(rel))
116+
ereport(ERROR,
117+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
118+
errmsg("cannot access temporary tables of other sessions")));
119+
110120
/*
111121
* Read metapage
112122
*/
@@ -262,6 +272,8 @@ pg_relpages(PG_FUNCTION_ARGS)
262272
relrv=makeRangeVarFromNameList(textToQualifiedNameList(relname));
263273
rel=relation_openrv(relrv,AccessShareLock);
264274

275+
/* note: this will work OK on non-local temp tables */
276+
265277
relpages=RelationGetNumberOfBlocks(rel);
266278

267279
relation_close(rel,AccessShareLock);

‎contrib/pgstattuple/pgstattuple.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.36 2008/06/19 00:46:03 alvherre Exp $
2+
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.37 2009/03/31 22:54:31 tgl Exp $
33
*
44
* Copyright (c) 2001,2002Tatsuo Ishii
55
*
@@ -199,6 +199,16 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
199199
{
200200
constchar*err;
201201

202+
/*
203+
* Reject attempts to read non-local temporary relations; we would
204+
* be likely to get wrong data since we have no visibility into the
205+
* owning session's local buffers.
206+
*/
207+
if (RELATION_IS_OTHER_TEMP(rel))
208+
ereport(ERROR,
209+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
210+
errmsg("cannot access temporary tables of other sessions")));
211+
202212
switch (rel->rd_rel->relkind)
203213
{
204214
caseRELKIND_RELATION:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp