]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Catch stack overflow when recursing in transformFromClauseItem().
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 13 Aug 2022 19:21:28 +0000 (15:21 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 13 Aug 2022 19:21:28 +0000 (15:21 -0400)
Most parts of the parser can expect that the stack overflow check
in transformExprRecurse() will trigger before things get desperate.
However, transformFromClauseItem() can recurse directly to self
without having analyzed any expressions, so it's possible to drive
it to a stack-overrun crash.  Add a check to prevent that.

Per bug #17583 from Egor Chindyaskin.  Back-patch to all supported
branches.

Richard Guo

Discussion: https://postgr.es/m/17583-33be55b9f981f75c@postgresql.org

src/backend/parser/parse_clause.c

index 7e9216142a190a873b55448950065061c0717bdf..0a0d68f0e7524852a774c81b13ca77d27619cffb 100644 (file)
@@ -1066,6 +1066,9 @@ transformFromClauseItem(ParseState *pstate, Node *n,
                                                RangeTblEntry **top_rte, int *top_rti,
                                                List **namespace)
 {
+       /* Guard against stack overflow due to overly deep subtree */
+       check_stack_depth();
+
        if (IsA(n, RangeVar))
        {
                /* Plain relation reference, or perhaps a CTE reference */