]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1405: missing check for out-of-memory v9.0.1405
authorBram Moolenaar <Bram@vim.org>
Wed, 15 Mar 2023 22:05:44 +0000 (22:05 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 15 Mar 2023 22:05:44 +0000 (22:05 +0000)
Problem:    Missing check for out-of-memory.
Solution:   Check for alloc() returning NULL pointer. (closes #12149)

src/option.c
src/version.c

index a2ab5c66635e9ac815db3b5eadf1092e0060dfa7..4d9da472fa4168b035872110ca362e570e276623 100644 (file)
@@ -126,15 +126,14 @@ set_init_default_backupskip(void)
 #endif
     int                len;
     garray_T   ga;
-    int                mustfree;
-    char_u             *item;
+    char_u     *item;
 
     opt_idx = findoption((char_u *)"backupskip");
 
     ga_init2(&ga, 1, 100);
     for (n = 0; n < (long)ARRAY_LENGTH(names); ++n)
     {
-       mustfree = FALSE;
+       int             mustfree = FALSE;
 #ifdef UNIX
        if (*names[n] == NUL)
 # ifdef MACOS_X
@@ -150,19 +149,22 @@ set_init_default_backupskip(void)
            // First time count the NUL, otherwise count the ','.
            len = (int)STRLEN(p) + 3;
            item = alloc(len);
-           STRCPY(item, p);
-           add_pathsep(item);
-           STRCAT(item, "*");
-           if (find_dup_item(ga.ga_data, item, options[opt_idx].flags)
-                   == NULL
-                   && ga_grow(&ga, len) == OK)
+           if (item != NULL)
            {
-               if (ga.ga_len > 0)
-                   STRCAT(ga.ga_data, ",");
-               STRCAT(ga.ga_data, item);
-               ga.ga_len += len;
+               STRCPY(item, p);
+               add_pathsep(item);
+               STRCAT(item, "*");
+               if (find_dup_item(ga.ga_data, item, options[opt_idx].flags)
+                                                                       == NULL
+                       && ga_grow(&ga, len) == OK)
+               {
+                   if (ga.ga_len > 0)
+                       STRCAT(ga.ga_data, ",");
+                   STRCAT(ga.ga_data, item);
+                   ga.ga_len += len;
+               }
+               vim_free(item);
            }
-           vim_free(item);
        }
        if (mustfree)
            vim_free(p);
index cad03e68111757afeba5c232a4067ffabf5caa3c..733eb46e175503093261a9963d03390702098702 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1405,
 /**/
     1404,
 /**/