summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2009-03-31 22:54:31 +0000
committerTom Lane2009-03-31 22:54:31 +0000
commitaae22715cce83440f6be344b346f9a3020d76fab (patch)
treece64897d77eb3ba72d4698e4a24b28bb7773f564
parent585d6f1d77604e84d3f0f7780a88e5592671b94c (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.
-rw-r--r--contrib/pageinspect/btreefuncs.c32
-rw-r--r--contrib/pageinspect/rawpage.c10
-rw-r--r--contrib/pgstattuple/pgstatindex.c14
-rw-r--r--contrib/pgstattuple/pgstattuple.c10
4 files changed, 64 insertions, 2 deletions
diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c
index 794704af59..425e00a95f 100644
--- a/contrib/pageinspect/btreefuncs.c
+++ b/contrib/pageinspect/btreefuncs.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*
*
* 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 17ca7d7d37..08d61fab87 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -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));
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index 2793b2aaa0..56fa800538 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*
*
* pgstatindex
@@ -108,6 +108,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 (RELATION_IS_OTHER_TEMP(rel))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
+ /*
* Read metapage
*/
{
@@ -262,6 +272,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 cce2676a33..1c475d6362 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -199,6 +199,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 (RELATION_IS_OTHER_TEMP(rel))
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot access temporary tables of other sessions")));
+
switch (rel->rd_rel->relkind)
{
case RELKIND_RELATION: