mirror of
https://github.com/postgres/postgres.git
synced 2025-05-31 00:01:57 -04:00
Install check_stack_depth() protection in two recursive tsquery
processing routines. Per Heikki.
This commit is contained in:
parent
ac20d3dfbe
commit
79048ca1a4
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.1 2007/08/21 01:11:19 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.2 2007/08/31 02:26:29 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -15,12 +15,14 @@
|
|||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
#include "libpq/pqformat.h"
|
#include "libpq/pqformat.h"
|
||||||
|
#include "miscadmin.h"
|
||||||
#include "tsearch/ts_locale.h"
|
#include "tsearch/ts_locale.h"
|
||||||
#include "tsearch/ts_type.h"
|
#include "tsearch/ts_type.h"
|
||||||
#include "tsearch/ts_utils.h"
|
#include "tsearch/ts_utils.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/pg_crc.h"
|
#include "utils/pg_crc.h"
|
||||||
|
|
||||||
|
|
||||||
/* parser's states */
|
/* parser's states */
|
||||||
#define WAITOPERAND 1
|
#define WAITOPERAND 1
|
||||||
#define WAITOPERATOR 2
|
#define WAITOPERATOR 2
|
||||||
@ -234,11 +236,13 @@ pushval_asis(TSQueryParserState * state, int type, char *strval, int lenval, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define STACKDEPTH 32
|
#define STACKDEPTH 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* make polish notation of query
|
* make polish notation of query
|
||||||
*/
|
*/
|
||||||
static int4
|
static int4
|
||||||
makepol(TSQueryParserState * state, void (*pushval) (TSQueryParserState *, int, char *, int, int2))
|
makepol(TSQueryParserState * state,
|
||||||
|
void (*pushval) (TSQueryParserState *, int, char *, int, int2))
|
||||||
{
|
{
|
||||||
int4 val = 0,
|
int4 val = 0,
|
||||||
type;
|
type;
|
||||||
@ -248,6 +252,9 @@ makepol(TSQueryParserState * state, void (*pushval) (TSQueryParserState *, int,
|
|||||||
int4 lenstack = 0;
|
int4 lenstack = 0;
|
||||||
int2 weight = 0;
|
int2 weight = 0;
|
||||||
|
|
||||||
|
/* since this function recurses, it could be driven to stack overflow */
|
||||||
|
check_stack_depth();
|
||||||
|
|
||||||
while ((type = gettoken_query(state, &val, &lenval, &strval, &weight)) != END)
|
while ((type = gettoken_query(state, &val, &lenval, &strval, &weight)) != END)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.1 2007/08/21 01:11:19 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.2 2007/08/31 02:26:29 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -19,6 +19,7 @@
|
|||||||
#include "executor/spi.h"
|
#include "executor/spi.h"
|
||||||
#include "funcapi.h"
|
#include "funcapi.h"
|
||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
|
#include "miscadmin.h"
|
||||||
#include "tsearch/ts_type.h"
|
#include "tsearch/ts_type.h"
|
||||||
#include "tsearch/ts_utils.h"
|
#include "tsearch/ts_utils.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
@ -525,14 +526,18 @@ checkcondition_str(void *checkval, QueryItem * val)
|
|||||||
* check for boolean condition
|
* check for boolean condition
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
TS_execute(QueryItem * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, QueryItem * val))
|
TS_execute(QueryItem * curitem, void *checkval, bool calcnot,
|
||||||
|
bool (*chkcond) (void *checkval, QueryItem * val))
|
||||||
{
|
{
|
||||||
|
/* since this function recurses, it could be driven to stack overflow */
|
||||||
|
check_stack_depth();
|
||||||
|
|
||||||
if (curitem->type == VAL)
|
if (curitem->type == VAL)
|
||||||
return chkcond(checkval, curitem);
|
return chkcond(checkval, curitem);
|
||||||
else if (curitem->val == (int4) '!')
|
else if (curitem->val == (int4) '!')
|
||||||
{
|
{
|
||||||
return (calcnot) ?
|
return (calcnot) ?
|
||||||
((TS_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
|
!TS_execute(curitem + 1, checkval, calcnot, chkcond)
|
||||||
: true;
|
: true;
|
||||||
}
|
}
|
||||||
else if (curitem->val == (int4) '&')
|
else if (curitem->val == (int4) '&')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user