Skip to content
Snippets Groups Projects
Commit c99e0d38 authored by Heikki Linnakangas's avatar Heikki Linnakangas
Browse files

Fix crash on compiling a regular expression with more than 32k colors.

Throw an error instead.

Backpatch to all supported branches.
parent 9508754e
No related branches found
No related tags found
No related merge requests found
...@@ -247,7 +247,15 @@ newcolor(struct colormap * cm) ...@@ -247,7 +247,15 @@ newcolor(struct colormap * cm)
/* oops, must allocate more */ /* oops, must allocate more */
struct colordesc *newCd; struct colordesc *newCd;
if (cm->max == MAX_COLOR)
{
CERR(REG_ECOLORS);
return COLORLESS; /* too many colors */
}
n = cm->ncds * 2; n = cm->ncds * 2;
if (n > MAX_COLOR + 1)
n = MAX_COLOR + 1;
if (cm->cd == cm->cdspace) if (cm->cd == cm->cdspace)
{ {
newCd = (struct colordesc *) MALLOC(n * sizeof(struct colordesc)); newCd = (struct colordesc *) MALLOC(n * sizeof(struct colordesc));
......
...@@ -77,3 +77,7 @@ ...@@ -77,3 +77,7 @@
{ {
REG_ETOOBIG, "REG_ETOOBIG", "nfa has too many states" REG_ETOOBIG, "REG_ETOOBIG", "nfa has too many states"
}, },
{
REG_ECOLORS, "REG_ECOLORS", "too many colors"
},
...@@ -153,6 +153,7 @@ typedef struct ...@@ -153,6 +153,7 @@ typedef struct
#define REG_MIXED 17 /* character widths of regex and string differ */ #define REG_MIXED 17 /* character widths of regex and string differ */
#define REG_BADOPT 18 /* invalid embedded option */ #define REG_BADOPT 18 /* invalid embedded option */
#define REG_ETOOBIG 19 /* nfa has too many states */ #define REG_ETOOBIG 19 /* nfa has too many states */
#define REG_ECOLORS 20 /* too many colors */
/* two specials for debugging and testing */ /* two specials for debugging and testing */
#define REG_ATOI 101 /* convert error-code name to number */ #define REG_ATOI 101 /* convert error-code name to number */
#define REG_ITOA 102 /* convert error-code number to name */ #define REG_ITOA 102 /* convert error-code number to name */
......
...@@ -148,6 +148,7 @@ ...@@ -148,6 +148,7 @@
typedef short color; /* colors of characters */ typedef short color; /* colors of characters */
typedef int pcolor; /* what color promotes to */ typedef int pcolor; /* what color promotes to */
#define MAX_COLOR 32767 /* max color (must fit in 'color' datatype) */
#define COLORLESS (-1) /* impossible color */ #define COLORLESS (-1) /* impossible color */
#define WHITE 0 /* default color, parent of all others */ #define WHITE 0 /* default color, parent of all others */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment