aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-03-31 22:54:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-03-31 22:54:52 +0000
commitb55266444783c0a9bbe96353b8e276dc12ff2958 (patch)
tree48c97b1a97a96abf361170181dd5c8891c7c4a38
parent9a427cde74718a02abd9c699e1d2d4ee223584c7 (diff)
downloadpostgresql-b55266444783c0a9bbe96353b8e276dc12ff2958.tar.gz
postgresql-b55266444783c0a9bbe96353b8e276dc12ff2958.zip
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.
-rw-r--r--contrib/pageinspect/btreefuncs.c30
-rw-r--r--contrib/pageinspect/rawpage.c12
-rw-r--r--contrib/pgstattuple/pgstatindex.c12
-rw-r--r--contrib/pgstattuple/pgstattuple.c12
4 files changed, 64 insertions, 2 deletions
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index ce8b97e46ba..c50c5da0bdb 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -186,6 +186,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 (isOtherTempNamespace(RelationGetNamespace(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");
@@ -294,6 +304,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 (isOtherTempNamespace(RelationGetNamespace(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");
@@ -433,6 +453,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 (isOtherTempNamespace(RelationGetNamespace(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 230d27133b8..75ab6fbfa32 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -8,7 +8,7 @@
* Copyright (c) 2007-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.4 2008/01/01 20:31:21 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pageinspect/rawpage.c,v 1.4.2.1 2009/03/31 22:54:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -68,6 +68,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 (isOtherTempNamespace(RelationGetNamespace(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));
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index 3cd31478956..f766739d744 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -104,6 +104,16 @@ pgstatindex(PG_FUNCTION_ARGS)
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 (isOtherTempNamespace(RelationGetNamespace(rel)))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
+ /*
* Read metapage
*/
{
@@ -261,6 +271,8 @@ pg_relpages(PG_FUNCTION_ARGS)
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
rel = relation_openrv(relrv, AccessShareLock);
+ /* note: this will work OK on non-local temp tables */
+
relpages = RelationGetNumberOfBlocks(rel);
relation_close(rel, AccessShareLock);
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c
index d252e23847d..989911fdd88 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.32 2008/01/14 02:53:31 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.32.2.1 2009/03/31 22:54:52 tgl Exp $
*
* Copyright (c) 2001,2002 Tatsuo Ishii
*
@@ -196,6 +196,16 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
{
const char *err;
+ /*
+ * 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 (isOtherTempNamespace(RelationGetNamespace(rel)))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
switch (rel->rd_rel->relkind)
{
case RELKIND_RELATION: