]> granicus.if.org Git - postgresql/commitdiff
Prevent stack overflow in query-type functions.
authorNoah Misch <noah@leadboat.com>
Mon, 5 Oct 2015 14:06:30 +0000 (10:06 -0400)
committerNoah Misch <noah@leadboat.com>
Mon, 5 Oct 2015 14:06:30 +0000 (10:06 -0400)
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).

contrib/intarray/_int_bool.c
contrib/ltree/ltxtquery_io.c
contrib/ltree/ltxtquery_op.c
src/backend/utils/adt/tsquery_cleanup.c

index c3c39d194bc89e9bf49139f9cd5819b066c66d2f..5d9e676660fd903354ad7deeb9fcef2603e7580e 100644 (file)
@@ -564,6 +564,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);
index ddc63d7b66b193599fdc92591db58138d7965896..74010f3cef4d6d4c052742c5614e9fe140105ec3 100644 (file)
@@ -416,6 +416,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;
index 64f9d219f76785dd08336c450fea6109e7e0733b..1428c8b47806f2c84b0fa5530c8d0b2f80ca2db8 100644 (file)
@@ -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 == (int32) '!')
index 2545f4eea7c0ad18dd09beeb8ec05e5e4b1daac2..b841006dd0f880c8e4511caadf2320f908064427 100644 (file)
@@ -33,6 +33,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)