From 00ac61695e5c7d573b14bb7a61387a3fae017928 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 13 Aug 2022 15:21:28 -0400 Subject: [PATCH] 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 c655d188c76..02c2d6afa35 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -1056,6 +1056,9 @@ transformFromClauseItem(ParseState *pstate, Node *n, ParseNamespaceItem **top_nsitem, 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 */