Skip to content

Commit 0140bee

Browse files
committed
Check for interrupts and stack overflow during rule/view dumps.
Since ruleutils.c recurses, it could be driven to stack overflow by deeply nested constructs. Very large queries might also take long enough to deparse that a check for interrupts seems like a good idea. Stick appropriate tests into a couple of key places. Noted by Greg Stark. Back-patch to all supported branches.
1 parent 0652d77 commit 0140bee

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "commands/tablespace.h"
3737
#include "executor/spi.h"
3838
#include "funcapi.h"
39+
#include "miscadmin.h"
3940
#include "nodes/makefuncs.h"
4041
#include "nodes/nodeFuncs.h"
4142
#include "optimizer/clauses.h"
@@ -4000,6 +4001,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
40004001
deparse_context context;
40014002
deparse_namespace dpns;
40024003

4004+
/* Guard against excessively long or deeply-nested queries */
4005+
CHECK_FOR_INTERRUPTS();
4006+
check_stack_depth();
4007+
40034008
/*
40044009
* Before we begin to examine the query, acquire locks on referenced
40054010
* relations, and fix up deleted columns in JOIN RTEs. This ensures
@@ -4556,6 +4561,10 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
45564561
StringInfo buf = context->buf;
45574562
bool need_paren;
45584563

4564+
/* Guard against excessively long or deeply-nested queries */
4565+
CHECK_FOR_INTERRUPTS();
4566+
check_stack_depth();
4567+
45594568
if (IsA(setOp, RangeTblRef))
45604569
{
45614570
RangeTblRef *rtr = (RangeTblRef *) setOp;
@@ -6393,6 +6402,10 @@ get_rule_expr(Node *node, deparse_context *context,
63936402
if (node == NULL)
63946403
return;
63956404

6405+
/* Guard against excessively long or deeply-nested queries */
6406+
CHECK_FOR_INTERRUPTS();
6407+
check_stack_depth();
6408+
63966409
/*
63976410
* Each level of get_rule_expr must emit an indivisible term
63986411
* (parenthesized if necessary) to ensure result is reparsed into the same

0 commit comments

Comments
 (0)