diff options
author | Heikki Linnakangas | 2013-04-04 16:04:57 +0000 |
---|---|---|
committer | Heikki Linnakangas | 2013-04-04 16:48:11 +0000 |
commit | bf2b0a147857f63daa2e5c17eed0169861371af8 (patch) | |
tree | c075c53dbb17fddcec93e53c1bd097e5e26af4ff | |
parent | d7d5832012ae5174707643af1a450d26d3350719 (diff) |
Fix crash on compiling a regular expression with more than 32k colors.
Throw an error instead.
Backpatch to all supported branches.
-rw-r--r-- | src/backend/regex/regc_color.c | 8 | ||||
-rw-r--r-- | src/include/regex/regerrs.h | 4 | ||||
-rw-r--r-- | src/include/regex/regex.h | 1 | ||||
-rw-r--r-- | src/include/regex/regguts.h | 1 |
4 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/regex/regc_color.c b/src/backend/regex/regc_color.c index 1c60566fbf5..e6aa899518f 100644 --- a/src/backend/regex/regc_color.c +++ b/src/backend/regex/regc_color.c @@ -247,7 +247,15 @@ newcolor(struct colormap * cm) /* oops, must allocate more */ struct colordesc *newCd; + if (cm->max == MAX_COLOR) + { + CERR(REG_ECOLORS); + return COLORLESS; /* too many colors */ + } + n = cm->ncds * 2; + if (n > MAX_COLOR + 1) + n = MAX_COLOR + 1; if (cm->cd == cm->cdspace) { newCd = (struct colordesc *) MALLOC(n * sizeof(struct colordesc)); diff --git a/src/include/regex/regerrs.h b/src/include/regex/regerrs.h index a761371e5d7..f02711ee176 100644 --- a/src/include/regex/regerrs.h +++ b/src/include/regex/regerrs.h @@ -77,3 +77,7 @@ { REG_ETOOBIG, "REG_ETOOBIG", "nfa has too many states" }, + +{ + REG_ECOLORS, "REG_ECOLORS", "too many colors" +}, diff --git a/src/include/regex/regex.h b/src/include/regex/regex.h index 616c2c6450d..3e87dff17b2 100644 --- a/src/include/regex/regex.h +++ b/src/include/regex/regex.h @@ -153,6 +153,7 @@ typedef struct #define REG_MIXED 17 /* character widths of regex and string differ */ #define REG_BADOPT 18 /* invalid embedded option */ #define REG_ETOOBIG 19 /* nfa has too many states */ +#define REG_ECOLORS 20 /* too many colors */ /* two specials for debugging and testing */ #define REG_ATOI 101 /* convert error-code name to number */ #define REG_ITOA 102 /* convert error-code number to name */ diff --git a/src/include/regex/regguts.h b/src/include/regex/regguts.h index e1e406f4eaa..4e04abfa6f2 100644 --- a/src/include/regex/regguts.h +++ b/src/include/regex/regguts.h @@ -148,6 +148,7 @@ typedef short color; /* colors of characters */ typedef int pcolor; /* what color promotes to */ +#define MAX_COLOR 32767 /* max color (must fit in 'color' datatype) */ #define COLORLESS (-1) /* impossible color */ #define WHITE 0 /* default color, parent of all others */ |