summaryrefslogtreecommitdiff
path: root/contrib/pg_trgm/trgm_regexp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-02-21 19:46:46 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-02-21 19:46:46 -0500
commit6ee479abfc27a18c37fe77140d16d3ac31f4ac31 (patch)
treeb5ba1f609a26fed45b13933bc4a8d78634179ae1 /contrib/pg_trgm/trgm_regexp.c
parentea1268f6301cc7adce571cc9c5ebe8d9342a2ef4 (diff)
Fix invalid array access in trgm_regexp.c.
Brown-paper-bag bug in 08c0d6ad6: 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.
Diffstat (limited to 'contrib/pg_trgm/trgm_regexp.c')
-rw-r--r--contrib/pg_trgm/trgm_regexp.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index fcf03de32dc..bf1dea6352e 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -1220,7 +1220,7 @@ addArcs(TrgmNFA *trgmNFA, TrgmState *state)
for (i = 0; i < arcsCount; i++)
{
regex_arc_t *arc = &arcs[i];
- TrgmColorInfo *colorInfo = &trgmNFA->colorInfo[arc->co];
+ TrgmColorInfo *colorInfo;
/*
* Ignore non-expandable colors; addKey already handled the case.
@@ -1228,8 +1228,14 @@ addArcs(TrgmNFA *trgmNFA, TrgmState *state)
* We need no special check for WHITE or begin/end pseudocolors
* here. We don't need to do any processing for them, and they
* will be marked non-expandable since the regex engine will have
- * reported them that way.
+ * reported them that way. We do have to watch out for RAINBOW,
+ * which has a negative color number.
*/
+ if (arc->co < 0)
+ continue;
+ Assert(arc->co < trgmNFA->ncolors);
+
+ colorInfo = &trgmNFA->colorInfo[arc->co];
if (!colorInfo->expandable)
continue;