aboutsummaryrefslogtreecommitdiff
path: root/src/backend/regex/regc_lex.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-08-24 13:01:40 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-08-24 13:01:40 -0400
commit2d1f1523ce830bd59c10cf144993fdd0bba50478 (patch)
treea2110f1e53c6dda6feb694888b31a08de055e609 /src/backend/regex/regc_lex.c
parent3ccdeff7bf1971d4a4ecece02f3ba3ec64d4a3ad (diff)
downloadpostgresql-2d1f1523ce830bd59c10cf144993fdd0bba50478.tar.gz
postgresql-2d1f1523ce830bd59c10cf144993fdd0bba50478.zip
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/regc_lex.c')
-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 16664531641..d573032db67 100644
--- a/src/backend/regex/regc_lex.c
+++ b/src/backend/regex/regc_lex.c
@@ -278,6 +278,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 */
@@ -595,8 +597,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);