diff options
author | Noah Misch <noah@leadboat.com> | 2015-10-05 10:06:30 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2015-10-05 10:06:35 -0400 |
commit | 879877b00bb54ba9dcdef0d218bd36c4e5404d6f (patch) | |
tree | 54cea9388658325b24a7e9727d1f69a63807843d | |
parent | 9581e2699f6379e29151b0bef04ca45a06f5afe0 (diff) | |
download | postgresql-879877b00bb54ba9dcdef0d218bd36c4e5404d6f.tar.gz |
Prevent stack overflow in query-type functions.
The tsquery, ltxtquery and query_int data types have a common ancestor.
Having acquired check_stack_depth() calls independently, each was
missing at least one call. Back-patch to 9.0 (all supported versions).
-rw-r--r-- | contrib/intarray/_int_bool.c | 3 | ||||
-rw-r--r-- | contrib/ltree/ltxtquery_io.c | 3 | ||||
-rw-r--r-- | contrib/ltree/ltxtquery_op.c | 4 | ||||
-rw-r--r-- | src/backend/utils/adt/tsquery_cleanup.c | 3 |
4 files changed, 13 insertions, 0 deletions
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c index 43cc0d42d5..ac501b474b 100644 --- a/contrib/intarray/_int_bool.c +++ b/contrib/intarray/_int_bool.c @@ -575,6 +575,9 @@ typedef struct static void infix(INFIX *in, bool first) { + /* since this function recurses, it could be driven to stack overflow. */ + check_stack_depth(); + if (in->curpol->type == VAL) { RESIZEBUF(in, 11); diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c index 13ea58df3f..d0e4b7f7e2 100644 --- a/contrib/ltree/ltxtquery_io.c +++ b/contrib/ltree/ltxtquery_io.c @@ -420,6 +420,9 @@ while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \ static void infix(INFIX *in, bool first) { + /* since this function recurses, it could be driven to stack overflow. */ + check_stack_depth(); + if (in->curpol->type == VAL) { char *op = in->op + in->curpol->distance; diff --git a/contrib/ltree/ltxtquery_op.c b/contrib/ltree/ltxtquery_op.c index 1c13888605..8ffa240169 100644 --- a/contrib/ltree/ltxtquery_op.c +++ b/contrib/ltree/ltxtquery_op.c @@ -8,6 +8,7 @@ #include <ctype.h> #include "ltree.h" +#include "miscadmin.h" PG_FUNCTION_INFO_V1(ltxtq_exec); PG_FUNCTION_INFO_V1(ltxtq_rexec); @@ -18,6 +19,9 @@ PG_FUNCTION_INFO_V1(ltxtq_rexec); bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *val)) { + /* since this function recurses, it could be driven to stack overflow */ + check_stack_depth(); + if (curitem->type == VAL) return (*chkcond) (checkval, curitem); else if (curitem->val == (int4) '!') diff --git a/src/backend/utils/adt/tsquery_cleanup.c b/src/backend/utils/adt/tsquery_cleanup.c index 9feb4b796a..dd48e85731 100644 --- a/src/backend/utils/adt/tsquery_cleanup.c +++ b/src/backend/utils/adt/tsquery_cleanup.c @@ -34,6 +34,9 @@ maketree(QueryItem *in) { NODE *node = (NODE *) palloc(sizeof(NODE)); + /* since this function recurses, it could be driven to stack overflow. */ + check_stack_depth(); + node->valnode = in; node->right = node->left = NULL; if (in->type == QI_OPR) |