]> 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:36 +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 57c021983639fcd3048e074ffc027bd891b62a5d..1e971fc98e0bddc2d6c730d7ca6cad4b627c6430 100644 (file)
@@ -541,6 +541,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 2cbcc89f5077d3b2d6577f3e4b8f5315d20ec202..34a6a1c5f46a4eac5b8b799b6d3da05691600fc9 100644 (file)
@@ -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;
index 559c05e2bf7226429ee75e4a9e9b341772d26b4f..c77e8569533736ad08ed4e6fcada8971dfa0d505 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 == (int4) '!')
index 2ffa241cf8868c880fe69ee478b5c46363bb037b..ff698f918eaf5a365fe03d93e3b1617f0cf67fc6 100644 (file)
@@ -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)