Skip to content

Commit e757080

Browse files
committed
Make pg_regexec() robust against out-of-range search_start.
If search_start is greater than the length of the string, we should just return REG_NOMATCH immediately. (Note that the equality case should *not* be rejected, since the pattern might be able to match zero characters.) This guards various internal assumptions that the min of a range of string positions is not more than the max. Violation of those assumptions could allow an attempt to fetch string[search_start-1], possibly causing a crash. Jaime Casanova pointed out that this situation is reachable with the new regexp_xxx functions that accept a user-specified start position. I don't believe it's reachable via any in-core call site in v14 and below. However, extensions could possibly call pg_regexec with an out-of-range search_start, so let's back-patch the fix anyway. Discussion: https://postgr.es/m/20210911180357.GA6870@ahch-to
1 parent c1b7a6c commit e757080

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/backend/regex/regexec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ pg_regexec(regex_t *re,
200200
return REG_INVARG;
201201
if (re->re_csize != sizeof(chr))
202202
return REG_MIXED;
203+
if (search_start > len)
204+
return REG_NOMATCH;
203205

204206
/* Initialize locale-dependent support */
205207
pg_set_regex_collation(re->re_collation);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy