Skip to content

Commit 2faab1a

Browse files
committed
Check for stack overflow in transformSetOperationTree().
Since transformSetOperationTree() recurses, it can be driven to stack overflow with enough UNION/INTERSECT/EXCEPT clauses in a query. Add a check to ensure it fails cleanly instead of crashing. Per report from Matthew Gerber (though it's not clear whether this is the only thing going wrong for him). Historical note: I think the reasoning behind not putting a check here in the beginning was that the check in transformExpr() ought to be sufficient to guard the whole parser. However, because transformSetOperationTree() recurses all the way to the bottom of the set-operation tree before doing any analysis of the statement's expressions, that check doesn't save it.
1 parent 29d539b commit 2faab1a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/backend/parser/analyze.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "postgres.h"
2626

2727
#include "catalog/pg_type.h"
28+
#include "miscadmin.h"
2829
#include "nodes/makefuncs.h"
2930
#include "optimizer/clauses.h"
3031
#include "optimizer/var.h"
@@ -1238,6 +1239,9 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt)
12381239

12391240
Assert(stmt && IsA(stmt, SelectStmt));
12401241

1242+
/* Guard against stack overflow due to overly complex set-expressions */
1243+
check_stack_depth();
1244+
12411245
/*
12421246
* Validity-check both leaf and internal SELECTs for disallowed ops.
12431247
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy