Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6ee479a

Browse files
committed
Fix invalid array access in trgm_regexp.c.
Brown-paper-bag bug in 08c0d6a: I missed one place that needed to guard against RAINBOW arc colors. Remarkably, nothing noticed the invalid array access except buildfarm member thorntail. Thanks to Noah Misch for assistance with tracking this down.
1 parent ea1268f commit 6ee479a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

contrib/pg_trgm/trgm_regexp.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -1220,16 +1220,22 @@ addArcs(TrgmNFA *trgmNFA, TrgmState *state)
12201220
for (i = 0; i < arcsCount; i++)
12211221
{
12221222
regex_arc_t *arc = &arcs[i];
1223-
TrgmColorInfo *colorInfo = &trgmNFA->colorInfo[arc->co];
1223+
TrgmColorInfo *colorInfo;
12241224

12251225
/*
12261226
* Ignore non-expandable colors; addKey already handled the case.
12271227
*
12281228
* We need no special check for WHITE or begin/end pseudocolors
12291229
* here. We don't need to do any processing for them, and they
12301230
* will be marked non-expandable since the regex engine will have
1231-
* reported them that way.
1231+
* reported them that way. We do have to watch out for RAINBOW,
1232+
* which has a negative color number.
12321233
*/
1234+
if (arc->co < 0)
1235+
continue;
1236+
Assert(arc->co < trgmNFA->ncolors);
1237+
1238+
colorInfo = &trgmNFA->colorInfo[arc->co];
12331239
if (!colorInfo->expandable)
12341240
continue;
12351241

0 commit comments

Comments
 (0)