]> 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:35 +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 43cc0d42d5c246c5a8821e83af858391ab2efb18..ac501b474b7b0190947d786201ecf830da45533e 100644 (file)
@@ -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);
index 13ea58df3f556e382a96bcfde9bf2c2d3cee06a4..d0e4b7f7e223261e38112ac7e104bb931b9ea7ce 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 1c13888605833645d0d1797fcefa06e98fbd23e4..8ffa2401699821ddea6eec8a35666185673df903 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 9feb4b796a6487e8d3145b449899f89b95ddeea6..dd48e85731d0469af1c0a134a366a036dc3ee68d 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)