Skip to content

Commit bed3f6d

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 a0c02ed commit bed3f6d

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
@@ -564,6 +564,9 @@ typedef struct
564564
static void
565565
infix(INFIX *in, bool first)
566566
{
567+
/* since this function recurses, it could be driven to stack overflow. */
568+
check_stack_depth();
569+
567570
if (in->curpol->type == VAL)
568571
{
569572
RESIZEBUF(in, 11);

contrib/ltree/ltxtquery_io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
416416
static void
417417
infix(INFIX *in, bool first)
418418
{
419+
/* since this function recurses, it could be driven to stack overflow. */
420+
check_stack_depth();
421+
419422
if (in->curpol->type == VAL)
420423
{
421424
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy