8000 Reject non-ON-SELECT rules that are named "_RETURN". · postgres/postgres@e9377e3 · GitHub
[go: up one dir, main page]

Skip to content
  • Commit e9377e3

    Browse files
    committed
    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 6618c27 commit e9377e3

    File tree

    1 file changed

    +12
    -0
    lines changed

    1 file changed

    +12
    -0
    lines changed

    src/backend/rewrite/rewriteDefine.c

    Lines changed: 12 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -524,6 +524,18 @@ DefineQueryRewrite(const char *rulename,
    524524
    RelationGetDescr(event_relation),
    525525
    false, false);
    526526
    }
    527+
    528+
    /*
    529+
    * And finally, if it's not an ON SELECT rule then it must *not* be
    530+
    * named _RETURN. This prevents accidentally or maliciously replacing
    531+
    * a view's ON SELECT rule with some other kind of rule.
    532+
    */
    533+
    if (strcmp(rulename, ViewSelectRuleName) == 0)
    534+
    ereport(ERROR,
    535+
    (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
    536+
    errmsg("non-view rule for \"%s\" must not be named \"%s\"",
    537+
    RelationGetRelationName(event_relation),
    538+
    ViewSelectRuleName)));
    527539
    }
    528540

    529541
    /*

    0 commit comments

    Comments
     (0)
    0