8000 Prevent stack overflow in query-type functions. · percona/postgres@682a25d · GitHub
[go: up one dir, main page]

Skip to content

Commit 682a25d

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 0398e07 commit 682a25d

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
@@ -541,6 +541,9 @@ typedef struct
541541
static void
542542
infix(INFIX *in, bool first)
543543
{
544+
/* since this function recurses, it could be driven to stack overflow. */
545+
check_stack_depth();
546+
544547
if (in->curpol->type == VAL)
545548
{
546549
RESIZEBUF(in, 11);

contrib/ltree/ltxtquery_io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
420420
static void
421421
infix(INFIX *in, bool first)
422422
{
423+
/* since this function recurses, it could be driven to stack overflow. */
424+
check_stack_depth();
425+
423426
if (in->curpol->type == VAL)
424427
{
425428
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 == (int4) '!')

src/backend/utils/adt/tsquery_cleanup.c

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

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

0 commit comments

Comments
 (0)
0