Skip to content

Commit 920fbc1

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 e2558e0 commit 920fbc1

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"
@@ -2661,6 +2662,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
26612662
deparse_context context;
26622663
deparse_namespace dpns;
26632664

2665+
/* Guard against excessively long or deeply-nested queries */
2666+
CHECK_FOR_INTERRUPTS();
2667+
check_stack_depth();
2668+
26642669
/*
26652670
* Before we begin to examine the query, acquire locks on referenced
26662671
* relations, and fix up deleted columns in JOIN RTEs. This ensures
@@ -3178,6 +3183,10 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
31783183
StringInfo buf = context->buf;
31793184
bool need_paren;
31803185

3186+
/* Guard against excessively long or deeply-nested queries */
3187+
CHECK_FOR_INTERRUPTS();
3188+
check_stack_depth();
3189+
31813190
if (IsA(setOp, RangeTblRef))
31823191
{
31833192
RangeTblRef *rtr = (RangeTblRef *) setOp;
@@ -5001,6 +5010,10 @@ get_rule_expr(Node *node, deparse_context *context,
50015010
if (node == NULL)
50025011
return;
50035012

5013+
/* Guard against excessively long or deeply-nested queries */
5014+
CHECK_FOR_INTERRUPTS();
5015+
check_stack_depth();
5016+
50045017
/*
50055018
* Each level of get_rule_expr must emit an indivisible term
50065019
* (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