From: Tom Lane Date: Wed, 30 Apr 2014 17:46:29 +0000 (-0400) Subject: Check for interrupts and stack overflow during rule/view dumps. X-Git-Tag: REL8_4_22~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f49df9150b9a00f7934f025677975e2396efebcd;p=thirdparty%2Fpostgresql.git 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. --- diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 117c6259179..ea2bb65d3d5 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -35,6 +35,7 @@ #include "commands/tablespace.h" #include "executor/spi.h" #include "funcapi.h" +#include "miscadmin.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "optimizer/clauses.h" @@ -2265,6 +2266,10 @@ get_query_def(Query *query, StringInfo buf, List *parentnamespace, deparse_context context; deparse_namespace dpns; + /* Guard against excessively long or deeply-nested queries */ + CHECK_FOR_INTERRUPTS(); + check_stack_depth(); + /* * Before we begin to examine the query, acquire locks on referenced * 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, StringInfo buf = context->buf; bool need_paren; + /* Guard against excessively long or deeply-nested queries */ + CHECK_FOR_INTERRUPTS(); + check_stack_depth(); + if (IsA(setOp, RangeTblRef)) { RangeTblRef *rtr = (RangeTblRef *) setOp; @@ -4297,6 +4306,10 @@ get_rule_expr(Node *node, deparse_context *context, if (node == NULL) return; + /* Guard against excessively long or deeply-nested queries */ + CHECK_FOR_INTERRUPTS(); + check_stack_depth(); + /* * Each level of get_rule_expr must emit an indivisible term * (parenthesized if necessary) to ensure result is reparsed into the same