Skip to content

Commit c4252ec

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 c06b721 commit c4252ec

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
@@ -35,6 +35,7 @@
3535
#include "commands/tablespace.h"
3636
#include "executor/spi.h"
3737
#include "funcapi.h"
38+
#include "miscadmin.h"
3839
#include "nodes/makefuncs.h"
3940
#include "nodes/nodeFuncs.h"
4041
#include "optimizer/clauses.h"
@@ -2416,6 +2417,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
24162417
deparse_context context;
24172418
deparse_namespace dpns;
24182419

2420+
/* Guard against excessively long or deeply-nested queries */
2421+
CHECK_FOR_INTERRUPTS();
2422+
check_stack_depth();
2423+
24192424
/*
24202425
* Before we begin to examine the query, acquire locks on referenced
24212426
* relations, and fix up deleted columns in JOIN RTEs. This ensures
@@ -2866,6 +2871,10 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
28662871
StringInfo buf = context->buf;
28672872
bool need_paren;
28682873

2874+
/* Guard against excessively long or deeply-nested queries */
2875+
CHECK_FOR_INTERRUPTS();
2876+
check_stack_depth();
2877+
28692878
if (IsA(setOp, RangeTblRef))
28702879
{
28712880
RangeTblRef *rtr = (RangeTblRef *) setOp;
@@ -4512,6 +4521,10 @@ get_rule_expr(Node *node, deparse_context *context,
45124521
if (node == NULL)
45134522
return;
45144523

4524+
/* Guard against excessively long or deeply-nested queries */
4525+
CHECK_FOR_INTERRUPTS();
4526+
check_stack_depth();
4527+
45154528
/*
45164529
* Each level of get_rule_expr must emit an indivisible term
45174530
* (parenthesized if necessary) to ensure result is reparsed into the same

0 commit comments

Comments
 (0)