summaryrefslogtreecommitdiff
path: root/src/backend/regex
diff options
context:
space:
mode:
authorTom Lane2022-08-24 17:01:40 +0000
committerTom Lane2022-08-24 17:02:19 +0000
commitf25bed3801e1e500850a9f3b29a003c644d4bd6d (patch)
tree57901ce20c082109be95173e61fffb0dff4e2b0a /src/backend/regex
parenta73d6c87f2eb19681fe52d6d8bb7db38a7a7da2a (diff)
Defend against stack overrun in a few more places.
SplitToVariants() in the ispell code, lseg_inside_poly() in geo_ops.c, and regex_selectivity_sub() in selectivity estimation could recurse until stack overflow; fix by adding check_stack_depth() calls. So could next() in the regex compiler, but that case is better fixed by converting its tail recursion to a loop. (We probably get better code that way too, since next() can now be inlined into its sole caller.) There remains a reachable stack overrun in the Turkish stemmer, but we'll need some advice from the Snowball people about how to fix that. Per report from Egor Chindyaskin and Alexander Lakhin. These mistakes are old, so back-patch to all supported branches. Richard Guo and Tom Lane Discussion: https://postgr.es/m/1661334672.728714027@f473.i.mail.ru
Diffstat (limited to 'src/backend/regex')
-rw-r--r--src/backend/regex/regc_lex.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/regex/regc_lex.c b/src/backend/regex/regc_lex.c
index 45727ffa01f..4780d79f097 100644
--- a/src/backend/regex/regc_lex.c
+++ b/src/backend/regex/regc_lex.c
@@ -201,6 +201,8 @@ next(struct vars *v)
{
chr c;
+next_restart: /* loop here after eating a comment */
+
/* errors yield an infinite sequence of failures */
if (ISERR())
return 0; /* the error has set nexttype to EOS */
@@ -493,8 +495,7 @@ next(struct vars *v)
if (!ATEOS())
v->now++;
assert(v->nexttype == v->lasttype);
- return next(v);
- break;
+ goto next_restart;
case CHR('='): /* positive lookahead */
NOTE(REG_ULOOKAROUND);
RETV(LACON, LATYPE_AHEAD_POS);