Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79048ca

Browse files
committed
Install check_stack_depth() protection in two recursive tsquery
processing routines. Per Heikki.
1 parentac20d3d commit79048ca

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
#defineWAITOPERAND 1
2628
#defineWAITOPERATOR2
@@ -234,11 +236,13 @@ pushval_asis(TSQueryParserState * state, int type, char *strval, int lenval, int
234236
}
235237

236238
#defineSTACKDEPTH32
239+
237240
/*
238241
* make polish notation of query
239242
*/
240243
staticint4
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
int4val=0,
244248
type;
@@ -248,6 +252,9 @@ makepol(TSQueryParserState * state, void (*pushval) (TSQueryParserState *, int,
248252
int4lenstack=0;
249253
int2weight=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,boolcalcnot,bool (*chkcond) (void*checkval,QueryItem*val))
529+
TS_execute(QueryItem*curitem,void*checkval,boolcalcnot,
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
returnchkcond(checkval,curitem);
532537
elseif (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
elseif (curitem->val== (int4)'&')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp