8000 Check for interrupts and stack overflow in TParserGet(). · postgres/postgres@c7f33a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7f33a1

Browse files
committed
Check for interrupts and stack overflow in TParserGet().
TParserGet() recurses for some token types, meaning it's possible to drive it to stack overflow. Since this is a minority behavior, I chose to add the check_stack_depth() call to the two places that recurse rather than doing it during every single call. While at it, add CHECK_FOR_INTERRUPTS(), because this can run unpleasantly long for long inputs. Per bug #17995 from Zuming Jiang. This is old, so back-patch to all supported branches. Discussion: https://postgr.es/m/17995-9f20ff3e6389db4c@postgresql.org
1 parent 96f9639 commit c7f33a1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/backend/tsearch/wparser_def.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "catalog/pg_collation.h"
2020
#include "commands/defrem.h"
21+
#include "miscadmin.h"
2122
#include "tsearch/ts_locale.h"
2223
#include "tsearch/ts_public.h"
2324
#include "tsearch/ts_type.h"
@@ -639,6 +640,12 @@ p_ishost(TParser *prs)
639640

640641
tmpprs->wanthost = true;
641642

643+
/*
644+
* Check stack depth before recursing. (Since TParserGet() doesn't
645+
* normally recurse, we put the cost of checking here not there.)
646+
*/
647+
check_stack_depth();
648+
642649
if (TParserGet(tmpprs) && tmpprs->type == HOST)
643650
{
644651
prs->state->posbyte += tmpprs->lenbytetoken;
@@ -662,6 +669,12 @@ p_isURLPath(TParser *prs)
662669
tmpprs->state = newTParserPosition(tmpprs->state);
663670
tmpprs->state->state = TPS_InURLPathFirst;
664671

672+
/*
673+
* Check stack depth before recursing. (Since TParserGet() doesn't
674+
* normally recurse, we put the cost of checking here not there.)
675+
*/
676+
check_stack_depth();
677+
665678
if (TParserGet(tmpprs) && tmpprs->type == URLPATH)
666679
{
667680
prs->state->posbyte += tmpprs->lenbytetoken;
@@ -1705,6 +1718,8 @@ TParserGet(TParser *prs)
17051718
{
17061719
const TParserStateActionItem *item = NULL;
17071720

1721+
CHECK_FOR_INTERRUPTS();
1722+
17081723
Assert(prs->state);
17091724

17101725
if (prs->state->posbyte >= prs->lenstr)

0 commit comments

Comments
 (0)
0