Commit 5976097c authored by Noah Misch's avatar Noah Misch

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).
parent 30cb1288
...@@ -564,6 +564,9 @@ typedef struct ...@@ -564,6 +564,9 @@ typedef struct
static void static void
infix(INFIX *in, bool first) infix(INFIX *in, bool first)
{ {
/* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
if (in->curpol->type == VAL) if (in->curpol->type == VAL)
{ {
RESIZEBUF(in, 11); RESIZEBUF(in, 11);
......
...@@ -416,6 +416,9 @@ while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \ ...@@ -416,6 +416,9 @@ while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
static void static void
infix(INFIX *in, bool first) infix(INFIX *in, bool first)
{ {
/* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
if (in->curpol->type == VAL) if (in->curpol->type == VAL)
{ {
char *op = in->op + in->curpol->distance; char *op = in->op + in->curpol->distance;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <ctype.h> #include <ctype.h>
#include "ltree.h" #include "ltree.h"
#include "miscadmin.h"
PG_FUNCTION_INFO_V1(ltxtq_exec); PG_FUNCTION_INFO_V1(ltxtq_exec);
PG_FUNCTION_INFO_V1(ltxtq_rexec); PG_FUNCTION_INFO_V1(ltxtq_rexec);
...@@ -18,6 +19,9 @@ PG_FUNCTION_INFO_V1(ltxtq_rexec); ...@@ -18,6 +19,9 @@ PG_FUNCTION_INFO_V1(ltxtq_rexec);
bool bool
ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *val)) 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) if (curitem->type == VAL)
return (*chkcond) (checkval, curitem); return (*chkcond) (checkval, curitem);
else if (curitem->val == (int32) '!') else if (curitem->val == (int32) '!')
......
...@@ -33,6 +33,9 @@ maketree(QueryItem *in) ...@@ -33,6 +33,9 @@ maketree(QueryItem *in)
{ {
NODE *node = (NODE *) palloc(sizeof(NODE)); NODE *node = (NODE *) palloc(sizeof(NODE));
/* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
node->valnode = in; node->valnode = in;
node->right = node->left = NULL; node->right = node->left = NULL;
if (in->type == QI_OPR) if (in->type == QI_OPR)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment