Skip to content

Commit 0bff398

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 41de93c commit 0bff398

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
@@ -37,6 +37,7 @@
3737
#include "commands/tablespace.h"
3838
#include "executor/spi.h"
3939
#include "funcapi.h"
40+
#include "miscadmin.h"
4041
#include "nodes/makefuncs.h"
4142
#include "nodes/nodeFuncs.h"
4243
#include "optimizer/tlist.h"
@@ -4133,6 +4134,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace,
41334134
deparse_context context;
41344135
deparse_namespace dpns;
41354136

4137+
/* Guard against excessively long or deeply-nested queries */
4138+
CHECK_FOR_INTERRUPTS();
4139+
check_stack_depth();
4140+
41364141
/*
41374142
* Before we begin to examine the query, acquire locks on referenced
41384143
* relations, and fix up deleted columns in JOIN RTEs. This ensures
@@ -4689,6 +4694,10 @@ get_setop_query(Node *setOp, Query *query, deparse_context *context,
46894694
StringInfo buf = context->buf;
46904695
bool need_paren;
46914696

4697+
/* Guard against excessively long or deeply-nested queries */
4698+
CHECK_FOR_INTERRUPTS();
4699+
check_stack_depth();
4700+
46924701
if (IsA(setOp, RangeTblRef))
46934702
{
46944703
RangeTblRef *rtr = (RangeTblRef *) setOp;
@@ -6526,6 +6535,10 @@ get_rule_expr(Node *node, deparse_context *context,
65266535
if (node == NULL)
65276536
return;
65286537

6538+
/* Guard against excessively long or deeply-nested queries */
6539+
CHECK_FOR_INTERRUPTS();
6540+
check_stack_depth();
6541+
65296542
/*
65306543
* Each level of get_rule_expr must emit an indivisible term
65316544
* (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