Skip to content

Commit f8ffe62

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 1458f0f commit f8ffe62

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
@@ -26,6 +26,7 @@
2626

2727
#include "access/sysattr.h"
2828
#include "catalog/pg_type.h"
29+
#include "miscadmin.h"
2930
#include "nodes/makefuncs.h"
3031
#include "nodes/nodeFuncs.h"
3132
#include "optimizer/var.h"
@@ -1520,6 +1521,9 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
15201521

15211522
Assert(stmt && IsA(stmt, SelectStmt));
15221523

1524+
/* Guard against stack overflow due to overly complex set-expressions */
1525+
check_stack_depth();
1526+
15231527
/*
15241528
* Validity-check both leaf and internal SELECTs for disallowed ops.
15251529
*/

0 commit comments

Comments
 (0)