Skip to content

Commit 0c7d3bb

Browse files
committed
Add missing array-enlargement logic to test_regex.c.
The stanza to report a "partial" match could overrun the initially allocated output array, so it needs its own copy of the array-resizing logic that's in the main loop. I overlooked the need for this in ca8217c. Per report from Alexander Lakhin. Discussion: https://postgr.es/m/3206aace-50db-e02a-bbea-76d5cdaa2cb6@gmail.com
1 parent cf621d9 commit 0c7d3bb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test/modules/test_regex/test_regex.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,18 @@ setup_test_matches(text *orig_str,
555555
*/
556556
if (matchctx->nmatches == 0 && re_flags->partial && re_flags->indices)
557557
{
558+
/* enlarge output space if needed */
559+
while (array_idx + matchctx->npatterns * 2 + 1 > array_len)
560+
{
561+
array_len += array_len + 1; /* 2^n-1 => 2^(n+1)-1 */
562+
if (array_len > MaxAllocSize / sizeof(int))
563+
ereport(ERROR,
564+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
565+
errmsg("too many regular expression matches")));
566+
matchctx->match_locs = (int *) repalloc(matchctx->match_locs,
567+
sizeof(int) * array_len);
568+
}
569+
558570
matchctx->match_locs[array_idx++] = matchctx->details.rm_extend.rm_so;
559571
matchctx->match_locs[array_idx++] = matchctx->details.rm_extend.rm_eo;
560572
/* we don't have pmatch data, so emit -1 */
@@ -566,6 +578,8 @@ setup_test_matches(text *orig_str,
566578
matchctx->nmatches++;
567579
}
568580

581+
Assert(array_idx <= array_len);
582+
569583
if (eml > 1)
570584
{
571585
int64 maxsiz = eml * (int64) maxlen;

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