Skip to content

Commit f49df91

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 e3f273f commit f49df91

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"
@@ -2265,6 +2266,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
22652266
deparse_context context;
22662267
deparse_namespace dpns;
22672268

2269+
/* Guard against excessively long or deeply-nested queries */
2270+
CHECK_FOR_INTERRUPTS();
2271+
check_stack_depth();
2272+
22682273
/*
22692274
* Before we begin to examine the query, acquire locks on referenced
22702275
* relations, and fix up deleted columns in JOIN RTEs. This ensures
@@ -2708,6 +2713,10 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
27082713
StringInfo buf = context->buf;
27092714
bool need_paren;
27102715

2716+
/* Guard against excessively long or deeply-nested queries */
2717+
CHECK_FOR_INTERRUPTS();
2718+
check_stack_depth();
2719+
27112720
if (IsA(setOp, RangeTblRef))
27122721
{
27132722
RangeTblRef *rtr = (RangeTblRef *) setOp;
@@ -4297,6 +4306,10 @@ get_rule_expr(Node *node, deparse_context *context,
42974306
if (node == NULL)
42984307
return;
42994308

4309+
/* Guard against excessively long or deeply-nested queries */
4310+
CHECK_FOR_INTERRUPTS();
4311+
check_stack_depth();
4312+
43004313
/*
43014314
* Each level of get_rule_expr must emit an indivisible term
43024315
* (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