Skip to content

Commit 380c15b

Browse files
tglsfdcreshke
authored andcommitted
Reject non-ON-SELECT rules that are named "_RETURN".
DefineQueryRewrite() has long required that ON SELECT rules be named "_RETURN". But we overlooked the converse case: we should forbid non-ON-SELECT rules that are named "_RETURN". In particular this prevents using CREATE OR REPLACE RULE to overwrite a view's _RETURN rule with some other kind of rule, thereby breaking the view. Per bug #17646 from Kui Liu. Back-patch to all supported branches. Discussion: https://postgr.es/m/17646-70c93cfa40365776@postgresql.org
1 parent de7e31a commit 380c15b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/backend/rewrite/rewriteDefine.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,18 @@ DefineQueryRewrite(const char *rulename,
578578
RelationGetDescr(event_relation),
579579
false, false);
580580
}
581+
582+
/*
583+
* And finally, if it's not an ON SELECT rule then it must *not* be
584+
* named _RETURN. This prevents accidentally or maliciously replacing
585+
* a view's ON SELECT rule with some other kind of rule.
586+
*/
587+
if (strcmp(rulename, ViewSelectRuleName) == 0)
588+
ereport(ERROR,
589+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
590+
errmsg("non-view rule for \"%s\" must not be named \"%s\"",
591+
RelationGetRelationName(event_relation),
592+
ViewSelectRuleName)));
581593
}
582594

583595
/*

0 commit comments

Comments
 (0)