aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-03-24 22:40:29 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-03-24 22:40:29 +0000
commit8899a2aba92c4a17f422172e7c9dd0e383eefa39 (patch)
treeaea400d25b0e9c32b84004728c995cd53ab33533 /src/backend/parser/parse_expr.c
parenta09b9a36d3cc8e4c5cd2877b2b764dc14a78f58e (diff)
downloadpostgresql-8899a2aba92c4a17f422172e7c9dd0e383eefa39.tar.gz
postgresql-8899a2aba92c4a17f422172e7c9dd0e383eefa39.zip
Replace max_expr_depth parameter with a max_stack_depth parameter that
is measured in kilobytes and checked against actual physical execution stack depth, as per my proposal of 30-Dec. This gives us a fairly bulletproof defense against crashing due to runaway recursive functions.
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c36
1 files changed, 3 insertions, 33 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 3881cc39538..83daae9b62b 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.166 2004/03/17 20:48:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.167 2004/03/24 22:40:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,9 +35,6 @@
#include "utils/syscache.h"
-int max_expr_depth = DEFAULT_MAX_EXPR_DEPTH;
-static int expr_depth_counter = 0;
-
bool Transform_null_equals = false;
static Node *typecast_expression(ParseState *pstate, Node *expr,
@@ -48,19 +45,6 @@ static Node *transformIndirection(ParseState *pstate, Node *basenode,
/*
- * Initialize for parsing a new query.
- *
- * We reset the expression depth counter here, in case it was left nonzero
- * due to ereport()'ing out of the last parsing operation.
- */
-void
-parse_expr_init(void)
-{
- expr_depth_counter = 0;
-}
-
-
-/*
* transformExpr -
* Analyze and transform expressions. Type checking and type casting is
* done here. The optimizer and the executor cannot handle the original
@@ -92,20 +76,8 @@ transformExpr(ParseState *pstate, Node *expr)
if (expr == NULL)
return NULL;
- /*
- * Guard against an overly complex expression leading to coredump due
- * to stack overflow here, or in later recursive routines that
- * traverse expression trees. Note that this is very unlikely to
- * happen except with pathological queries; but we don't want someone
- * to be able to crash the backend quite that easily...
- */
- if (++expr_depth_counter > max_expr_depth)
- ereport(ERROR,
- (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
- errmsg("expression too complex"),
- errdetail("Nesting depth exceeds maximum expression depth %d.",
- max_expr_depth),
- errhint("Increase the configuration parameter \"max_expr_depth\".")));
+ /* Guard against stack overflow due to overly complex expressions */
+ check_stack_depth();
switch (nodeTag(expr))
{
@@ -938,8 +910,6 @@ transformExpr(ParseState *pstate, Node *expr)
break;
}
- expr_depth_counter--;
-
return result;
}