]> granicus.if.org Git - vim/commitdiff
patch 8.1.0898: a messed up rgb.txt can crash Vim v8.1.0898
authorBram Moolenaar <Bram@vim.org>
Tue, 12 Feb 2019 19:46:48 +0000 (20:46 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 12 Feb 2019 19:46:48 +0000 (20:46 +0100)
Problem:    A messed up rgb.txt can crash Vim. (Pavel Cheremushkin)
Solution:   Limit to 10000 entries.  Also don't retry many times when the file
            cannot be read.

src/term.c
src/version.c

index 47d2bdafb11568132a31282d6654a004bf542754..be33fb92d5d4832c447ae8cb282ccbd583aad67f 100644 (file)
@@ -6985,13 +6985,13 @@ gui_get_color_cmn(char_u *name)
            return rgb_table[i].color;
 
     /*
-     * Last attempt. Look in the file "$VIM/rgb.txt".
+     * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt".
      */
     if (size == 0)
     {
        int counting;
 
-       /* colornames_table not yet initialized */
+       // colornames_table not yet initialized
        fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt");
        if (fname == NULL)
            return INVALCOLOR;
@@ -7002,6 +7002,7 @@ gui_get_color_cmn(char_u *name)
        {
            if (p_verbose > 1)
                verb_msg(_("Cannot open $VIMRUNTIME/rgb.txt"));
+           size = -1;  // don't try again
            return INVALCOLOR;
        }
 
@@ -7050,6 +7051,11 @@ gui_get_color_cmn(char_u *name)
                    colornames_table[size].color = (guicolor_T)RGB(r, g, b);
                }
                size++;
+
+               // The distributed rgb.txt has less than 1000 entries. Limit to
+               // 10000, just in case the file was messed up.
+               if (size == 10000)
+                   break;
            }
        }
        fclose(fd);
index 6e3d7806fb7888ec2669676f87cc7060e00dd37f..a2c250e52964c438ea8fbc6ab40b5cf694456c3a 100644 (file)
@@ -783,6 +783,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    898,
 /**/
     897,
 /**/