Skip to content

Commit

Permalink
Reject non-ON-SELECT rules that are named "_RETURN".
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tglsfdc committed Oct 17, 2022
1 parent 02d074e commit ecf4ce6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/backend/rewrite/rewriteDefine.c
Expand Up @@ -524,6 +524,18 @@ DefineQueryRewrite(char *rulename,
RelationGetDescr(event_relation),
false, false);
}

/*
* And finally, if it's not an ON SELECT rule then it must *not* be
* named _RETURN. This prevents accidentally or maliciously replacing
* a view's ON SELECT rule with some other kind of rule.
*/
if (strcmp(rulename, ViewSelectRuleName) == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("non-view rule for \"%s\" must not be named \"%s\"",
RelationGetRelationName(event_relation),
ViewSelectRuleName)));
}

/*
Expand Down

0 comments on commit ecf4ce6

Please sign in to comment.