diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-04-30 13:46:13 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-04-30 13:46:13 -0400 |
commit | 0bff398761b5e6119b40550bbe3751f4194dc7a7 (patch) | |
tree | bee7579cd7cbd91c68a3aa9797839bfa9d8a0f92 /src/backend/utils/adt/ruleutils.c | |
parent | 41de93c53aa941167d445ecb7d91d58829adcc92 (diff) | |
download | postgresql-0bff398761b5e6119b40550bbe3751f4194dc7a7.tar.gz postgresql-0bff398761b5e6119b40550bbe3751f4194dc7a7.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 957f0fc7d9f..78b23221b7a 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -37,6 +37,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/tlist.h" @@ -4133,6 +4134,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 @@ -4689,6 +4694,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; @@ -6526,6 +6535,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 |