Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a710713

Browse files
committed
Add checks to DefineQueryRewrite() to prohibit attaching rules to relations
that aren't RELKIND_RELATION or RELKIND_VIEW, and to disallow attaching rules to system relations unless allowSystemTableMods is on. This is to make the behavior of CREATE RULE more like CREATE TRIGGER, which disallows the comparable cases. Per discussion of bug #4808.
1 parent 1958603 commit a710713

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/rewrite/rewriteDefine.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.136 2009/01/27 12:40:15 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.137 2009/05/13 22:32:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include "postgres.h"
1616

1717
#include "access/heapam.h"
18+
#include "catalog/catalog.h"
1819
#include "catalog/dependency.h"
1920
#include "catalog/indexing.h"
2021
#include "catalog/namespace.h"
@@ -242,6 +243,22 @@ DefineQueryRewrite(char *rulename,
242243
*/
243244
event_relation = heap_open(event_relid, AccessExclusiveLock);
244245

246+
/*
247+
* Verify relation is of a type that rules can sensibly be applied to.
248+
*/
249+
if (event_relation->rd_rel->relkind != RELKIND_RELATION &&
250+
event_relation->rd_rel->relkind != RELKIND_VIEW)
251+
ereport(ERROR,
252+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
253+
errmsg("\"%s\" is not a table or view",
254+
RelationGetRelationName(event_relation))));
255+
256+
if (!allowSystemTableMods && IsSystemRelation(event_relation))
257+
ereport(ERROR,
258+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
259+
errmsg("permission denied: \"%s\" is a system catalog",
260+
RelationGetRelationName(event_relation))));
261+
245262
/*
246263
* Check user has permission to apply rules to this relation.
247264
*/

0 commit comments

Comments
 (0)