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

Commit bf2b0a1

Browse files
committed
Fix crash on compiling a regular expression with more than 32k colors.
Throw an error instead. Backpatch to all supported branches.
1 parent d7d5832 commit bf2b0a1

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/backend/regex/regc_color.c

+8
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,15 @@ newcolor(struct colormap * cm)
247247
/* oops, must allocate more */
248248
struct colordesc *newCd;
249249

250+
if (cm->max == MAX_COLOR)
251+
{
252+
CERR(REG_ECOLORS);
253+
return COLORLESS; /* too many colors */
254+
}
255+
250256
n = cm->ncds * 2;
257+
if (n > MAX_COLOR + 1)
258+
n = MAX_COLOR + 1;
251259
if (cm->cd == cm->cdspace)
252260
{
253261
newCd = (struct colordesc *) MALLOC(n * sizeof(struct colordesc));

src/include/regex/regerrs.h

+4
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@
7777
{
7878
REG_ETOOBIG, "REG_ETOOBIG", "nfa has too many states"
7979
},
80+
81+
{
82+
REG_ECOLORS, "REG_ECOLORS", "too many colors"
83+
},

src/include/regex/regex.h

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ typedef struct
153153
#define REG_MIXED 17 /* character widths of regex and string differ */
154154
#define REG_BADOPT 18 /* invalid embedded option */
155155
#define REG_ETOOBIG 19 /* nfa has too many states */
156+
#define REG_ECOLORS 20 /* too many colors */
156157
/* two specials for debugging and testing */
157158
#define REG_ATOI 101 /* convert error-code name to number */
158159
#define REG_ITOA 102 /* convert error-code number to name */

src/include/regex/regguts.h

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
typedef short color; /* colors of characters */
149149
typedef int pcolor; /* what color promotes to */
150150

151+
#define MAX_COLOR 32767 /* max color (must fit in 'color' datatype) */
151152
#define COLORLESS (-1) /* impossible color */
152153
#define WHITE 0 /* default color, parent of all others */
153154

0 commit comments

Comments
 (0)