postgres.git / summary / log / commit / refs

commit    ba516fb0715c75b1b2d393c3de7b99fca6a1ac67
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Sat Aug 13 19:21:28 2022 +0000
First released in: 16.0, 10.23, 11.18, 12.13, 13.9, 14.6, 15.0

    Catch stack overflow when recursing in transformFromClauseItem().
    
    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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 7e9216142a1..0a0d68f0e75 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -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 */ [parent: 1f71861a8540]