Skip to content

Commit 28dea94

Browse files
committed
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).
1 parent 9286ff7 commit 28dea94

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

contrib/intarray/_int_bool.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,9 @@ typedef struct
572572
static void
573573
infix(INFIX *in, bool first)
574574
{
575+
/* since this function recurses, it could be driven to stack overflow. */
576+
check_stack_depth();
577+
575578
if (in->curpol->type == VAL)
576579
{
577580
RESIZEBUF(in, 11);

contrib/ltree/ltxtquery_io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
419419
static void
420420
infix(INFIX *in, bool first)
421421
{
422+
/* since this function recurses, it could be driven to stack overflow. */
423+
check_stack_depth();
424+
422425
if (in->curpol->type == VAL)
423426
{
424427
char *op = in->op + in->curpol->distance;

contrib/ltree/ltxtquery_op.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ctype.h>
99

1010
#include "ltree.h"
11+
#include "miscadmin.h"
1112

1213
PG_FUNCTION_INFO_V1(ltxtq_exec);
1314
PG_FUNCTION_INFO_V1(ltxtq_rexec);
@@ -18,6 +19,9 @@ PG_FUNCTION_INFO_V1(ltxtq_rexec);
1819
bool
1920
ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *val))
2021
{
22+
/* since this function recurses, it could be driven to stack overflow */
23+
check_stack_depth();
24+
2125
if (curitem->type == VAL)
2226
return (*chkcond) (checkval, curitem);
2327
else if (curitem->val == (int32) '!')

src/backend/utils/adt/tsquery_cleanup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ maketree(QueryItem *in)
3333
{
3434
NODE *node = (NODE *) palloc(sizeof(NODE));
3535

36+
/* since this function recurses, it could be driven to stack overflow. */
37+
check_stack_depth();
38+
3639
node->valnode = in;
3740
node->right = node->left = NULL;
3841
if (in->type == QI_OPR)

0 commit comments

Comments
 (0)