Skip to content

Commit

Permalink
Require superuser to use pg_dirtyread
Browse files Browse the repository at this point in the history
Spotted by Andreas Seltenreich
  • Loading branch information
df7cb committed Apr 16, 2017
1 parent 35d7b0c commit 668923f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions expected/dirtyread.out
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ DETAIL: Attribute "dead" has type boolean in corresponding attribute of type fo
SELECT * FROM pg_dirtyread('foo'::regclass) as t(oid bigint);
ERROR: Error converting tuple descriptors!
DETAIL: Attribute "oid" has type oid in corresponding attribute of type foo.
SET ROLE luser;
SELECT * FROM pg_dirtyread('foo'::regclass) as t(bar bigint, baz text);
ERROR: must be superuser to use pg_dirtyread
4 changes: 4 additions & 0 deletions expected/extension.out
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
CREATE EXTENSION pg_dirtyread;
-- create a non-superuser role, ignoring any output/errors, it might already exist
SET client_min_messages = fatal;
\set QUIET on
CREATE ROLE luser;
6 changes: 6 additions & 0 deletions pg_dirtyread.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#if PG_VERSION_NUM >= 90300
#include "access/htup_details.h"
#endif
#include "miscadmin.h" /* superuser */
#include "storage/procarray.h" /* GetOldestXmin */

#include "dirtyread_tupconvert.h"
Expand Down Expand Up @@ -73,6 +74,11 @@ pg_dirtyread(PG_FUNCTION_ARGS)
Oid relid;
TupleDesc tupdesc;

if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to use pg_dirtyread")));

relid = PG_GETARG_OID(0);
if (!OidIsValid(relid))
elog(ERROR, "invalid relation oid \"%d\"", relid);
Expand Down
3 changes: 3 additions & 0 deletions sql/dirtyread.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ SELECT * FROM pg_dirtyread('foo'::regclass) as t(cmin bigint);
SELECT * FROM pg_dirtyread('foo'::regclass) as t(cmax bigint);
SELECT * FROM pg_dirtyread('foo'::regclass) as t(dead bigint);
SELECT * FROM pg_dirtyread('foo'::regclass) as t(oid bigint);

SET ROLE luser;
SELECT * FROM pg_dirtyread('foo'::regclass) as t(bar bigint, baz text);
5 changes: 5 additions & 0 deletions sql/extension.sql
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
CREATE EXTENSION pg_dirtyread;

-- create a non-superuser role, ignoring any output/errors, it might already exist
SET client_min_messages = fatal;
\set QUIET on
CREATE ROLE luser;

0 comments on commit 668923f

Please sign in to comment.