8000 Check for stack overflow in transformSetOperationTree(). · danielcode/postgres@454edf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 454edf1

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 9b06d91 commit 454edf1

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"
@@ -1558,6 +1559,9 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
15581559

15591560
Assert(stmt && IsA(stmt, SelectStmt));
15601561

1562+
/* Guard against stack overflow due to overly complex set-expressions */
1563+
check_stack_depth();
1564+
15611565
/*
15621566
* Validity-check both leaf and internal SELECTs for disallowed ops.
15631567
*/

0 commit comments

Comments
 (0)
0