]> granicus.if.org Git - postgresql/commitdiff
Fix crash on compiling a regular expression with more than 32k colors.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 4 Apr 2013 16:04:57 +0000 (19:04 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 4 Apr 2013 16:31:59 +0000 (19:31 +0300)
Throw an error instead.

Backpatch to all supported branches.

src/backend/regex/regc_color.c
src/include/regex/regerrs.h
src/include/regex/regex.h
src/include/regex/regguts.h

index 1c60566fbf57458a1f43a4116432e0636ebcd92d..e6aa899518fc36beb3f6a9ca78fe161958b4cfcc 100644 (file)
@@ -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));
index a761371e5d716a15e1cf112b2403d47327b749de..f02711ee1762604dee60ce2b99a3858dded91ccf 100644 (file)
@@ -77,3 +77,7 @@
 {
        REG_ETOOBIG, "REG_ETOOBIG", "nfa has too many states"
 },
+
+{
+       REG_ECOLORS, "REG_ECOLORS", "too many colors"
+},
index 616c2c6450d80443361ca7e4660f52aaa266c9ad..3e87dff17b27f6c622a9e9278a64ea7a2bc8abad 100644 (file)
@@ -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 */
index e1e406f4eaa77720d88938cf150348ce903f88d8..4e04abfa6f295ea235eeb8cbae61d1e9240ecde0 100644 (file)
 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 */