summaryrefslogtreecommitdiff
path: root/contrib/pageinspect
diff options
context:
space:
mode:
authorTom Lane2009-03-31 22:54:31 +0000
committerTom Lane2009-03-31 22:54:31 +0000
commitc029a6a49e3782ec5f1a61eb9a495ebd2a56077d (patch)
treefb92a2d210a1086b1fe7c4b83123c1f729ea57ec /contrib/pageinspect
parent572b60a3bd2af3c3ef75216cf6378025d7d317b1 (diff)
Fix contrib/pgstattuple and contrib/pageinspect to prevent attempts to read
temporary tables of other sessions; that is unsafe because of the way our buffer management works. Per report from Stuart Bishop. This is redundant with the bufmgr.c checks in HEAD, but not at all redundant in the back branches.
Diffstat (limited to 'contrib/pageinspect')
-rw-r--r--contrib/pageinspect/btreefuncs.c32
-rw-r--r--contrib/pageinspect/rawpage.c12
2 files changed, 42 insertions, 2 deletions
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index ab80b545000..85935b99905 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/pageinspect/btreefuncs.c,v 1.8 2008/05/17 01:28:19 adunstan Exp $
+ * $PostgreSQL: pgsql/contrib/pageinspect/btreefuncs.c,v 1.9 2009/03/31 22:54:31 tgl Exp $
*
*
* btreefuncs.c
@@ -190,6 +190,16 @@ bt_page_stats(PG_FUNCTION_ARGS)
elog(ERROR, "relation \"%s\" is not a btree index",
RelationGetRelationName(rel));
+ /*
+ * Reject attempts to read non-local temporary relations; we would
+ * be likely to get wrong data since we have no visibility into the
+ * owning session's local buffers.
+ */
+ if (RELATION_IS_OTHER_TEMP(rel))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
if (blkno == 0)
elog(ERROR, "block 0 is a meta page");
@@ -298,6 +308,16 @@ bt_page_items(PG_FUNCTION_ARGS)
elog(ERROR, "relation \"%s\" is not a btree index",
RelationGetRelationName(rel));
+ /*
+ * Reject attempts to read non-local temporary relations; we would
+ * be likely to get wrong data since we have no visibility into the
+ * owning session's local buffers.
+ */
+ if (RELATION_IS_OTHER_TEMP(rel))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
if (blkno == 0)
elog(ERROR, "block 0 is a meta page");
@@ -437,6 +457,16 @@ bt_metap(PG_FUNCTION_ARGS)
elog(ERROR, "relation \"%s\" is not a btree index",
RelationGetRelationName(rel));
+ /*
+ * Reject attempts to read non-local temporary relations; we would
+ * be likely to get wrong data since we have no visibility into the
+ * owning session's local buffers.
+ */
+ if (RELATION_IS_OTHER_TEMP(rel))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
buffer = ReadBuffer(rel, 0);
page = BufferGetPage(buffer);
metad = BTPageGetMeta(page);
diff --git a/contrib/pageinspect/rawpage.c b/contrib/pageinspect/rawpage.c
index 607f55eef0a..91b6a1915f0 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -8,7 +8,7 @@
* Copyright (c) 2007-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.10 2009/01/01 17:23:32 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.11 2009/03/31 22:54:31 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -74,6 +74,16 @@ get_raw_page(PG_FUNCTION_ARGS)
errmsg("cannot get raw page from composite type \"%s\"",
RelationGetRelationName(rel))));
+ /*
+ * Reject attempts to read non-local temporary relations; we would
+ * be likely to get wrong data since we have no visibility into the
+ * owning session's local buffers.
+ */
+ if (RELATION_IS_OTHER_TEMP(rel))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
if (blkno >= RelationGetNumberOfBlocks(rel))
elog(ERROR, "block number %u is out of range for relation \"%s\"",
blkno, RelationGetRelationName(rel));