]> 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:32:13 +0000 (19:32 +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 99c28505ae92213967afdcb13205c924acc9d999..846f24f7c284742f6499932d2dc267e95e371185 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 b8cc1f3da73f46a2368c30fee40bd82b63d40c9c..15da324b66041534117169c7e6c3f54a889333a7 100644 (file)
@@ -77,3 +77,7 @@
 {
        REG_ETOOBIG, "REG_ETOOBIG", "nfa has too many states"
 },
+
+{
+       REG_ECOLORS, "REG_ECOLORS", "too many colors"
+},
index d198864e90e5d73a68a0a4877fc8e4542f9385c9..adaf1a168d7d49812137e2c58c341d0edc7b1180 100644 (file)
@@ -152,6 +152,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 973e99a0823b8c3100d516aa00b612c2200854b1..9cd0ef9fdf6d07fa30d65c0729c68241a68fb1a4 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 */