Skip to content

Commit 3897ee9

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 94095e3 commit 3897ee9

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"
@@ -2608,6 +2609,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
26082609
deparse_context context;
26092610
deparse_namespace dpns;
26102611

2612+
/* Guard against excessively long or deeply-nested queries */
2613+
CHECK_FOR_INTERRUPTS();
2614+
check_stack_depth();
2615+
26112616
/*
26122617
* Before we begin to examine the query, acquire locks on referenced
26132618
* relations, and fix up deleted columns in JOIN RTEs. This ensures
@@ -3057,6 +3062,10 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
30573062
StringInfo buf = context->buf;
30583063
bool need_paren;
30593064

3065+
/* Guard against excessively long or deeply-nested queries */
3066+
CHECK_FOR_INTERRUPTS();
3067+
check_stack_depth();
3068+
30603069
if (IsA(setOp, RangeTblRef))
30613070
{
30623071
RangeTblRef *rtr = (RangeTblRef *) setOp;
@@ -4842,6 +4851,10 @@ get_rule_expr(Node *node, deparse_context *context,
48424851
if (node == NULL)
48434852
return;
48444853

4854+
/* Guard against excessively long or deeply-nested queries */
4855+
CHECK_FOR_INTERRUPTS();
4856+
check_stack_depth();
4857+
48454858
/*
48464859
* Each level of get_rule_expr must emit an indivisible term
48474860
* (parenthesized if necessary) to ensure result is reparsed into the same

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