Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 79048ca

Browse files
committed
Install check_stack_depth() protection in two recursive tsquery
processing routines. Per Heikki.
1 parent ac20d3d commit 79048ca

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/backend/utils/adt/tsquery.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.1 2007/08/21 01:11:19 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.2 2007/08/31 02:26:29 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include "postgres.h"
1616

1717
#include "libpq/pqformat.h"
18+
#include "miscadmin.h"
1819
#include "tsearch/ts_locale.h"
1920
#include "tsearch/ts_type.h"
2021
#include "tsearch/ts_utils.h"
2122
#include "utils/memutils.h"
2223
#include "utils/pg_crc.h"
2324

25+
2426
/* parser's states */
2527
#define WAITOPERAND 1
2628
#define WAITOPERATOR 2
@@ -234,11 +236,13 @@ pushval_asis(TSQueryParserState * state, int type, char *strval, int lenval, int
234236
}
235237

236238
#define STACKDEPTH 32
239+
237240
/*
238241
* make polish notation of query
239242
*/
240243
static int4
241-
makepol(TSQueryParserState * state, void (*pushval) (TSQueryParserState *, int, char *, int, int2))
244+
makepol(TSQueryParserState * state,
245+
void (*pushval) (TSQueryParserState *, int, char *, int, int2))
242246
{
243247
int4 val = 0,
244248
type;
@@ -248,6 +252,9 @@ makepol(TSQueryParserState * state, void (*pushval) (TSQueryParserState *, int,
248252
int4 lenstack = 0;
249253
int2 weight = 0;
250254

255+
/* since this function recurses, it could be driven to stack overflow */
256+
check_stack_depth();
257+
251258
while ((type = gettoken_query(state, &val, &lenval, &strval, &weight)) != END)
252259
{
253260
switch (type)

src/backend/utils/adt/tsvector_op.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.1 2007/08/21 01:11:19 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.2 2007/08/31 02:26:29 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -19,6 +19,7 @@
1919
#include "executor/spi.h"
2020
#include "funcapi.h"
2121
#include "mb/pg_wchar.h"
22+
#include "miscadmin.h"
2223
#include "tsearch/ts_type.h"
2324
#include "tsearch/ts_utils.h"
2425
#include "utils/builtins.h"
@@ -525,14 +526,18 @@ checkcondition_str(void *checkval, QueryItem * val)
525526
* check for boolean condition
526527
*/
527528
bool
528-
TS_execute(QueryItem * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, QueryItem * val))
529+
TS_execute(QueryItem * curitem, void *checkval, bool calcnot,
530+
bool (*chkcond) (void *checkval, QueryItem * val))
529531
{
532+
/* since this function recurses, it could be driven to stack overflow */
533+
check_stack_depth();
534+
530535
if (curitem->type == VAL)
531536
return chkcond(checkval, curitem);
532537
else if (curitem->val == (int4) '!')
533538
{
534539
return (calcnot) ?
535-
((TS_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
540+
!TS_execute(curitem + 1, checkval, calcnot, chkcond)
536541
: true;
537542
}
538543
else if (curitem->val == (int4) '&')

0 commit comments

Comments
 (0)