]> granicus.if.org Git - vim/commitdiff
patch 8.2.4362: :retab may allocate too much memory v8.2.4362
authorBram Moolenaar <Bram@vim.org>
Sat, 12 Feb 2022 20:46:15 +0000 (20:46 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 12 Feb 2022 20:46:15 +0000 (20:46 +0000)
Problem:    :retab may allocate too much memory.
Solution:   Bail out when allocating more than MAXCOL bytes.

src/indent.c
src/version.c

index 232c534973af6b94a2e2f725ca1b27c5d8e46518..3148495db1563fbe23d4504387b5b130d151b87d 100644 (file)
@@ -1607,6 +1607,7 @@ ex_retab(exarg_T *eap)
     long       start_col = 0;          // For start of white-space string
     long       start_vcol = 0;         // For start of white-space string
     long       old_len;
+    long       new_len;
     char_u     *ptr;
     char_u     *new_line = (char_u *)1; // init to non-NULL
     int                did_undo;               // called u_save for current line
@@ -1724,7 +1725,13 @@ ex_retab(exarg_T *eap)
                        // len is actual number of white characters used
                        len = num_spaces + num_tabs;
                        old_len = (long)STRLEN(ptr);
-                       new_line = alloc(old_len - col + start_col + len + 1);
+                       new_len = old_len - col + start_col + len + 1;
+                       if (new_len >= MAXCOL)
+                       {
+                           emsg(_(e_resulting_text_too_long));
+                           break;
+                       }
+                       new_line = alloc(new_len);
                        if (new_line == NULL)
                            break;
                        if (start_col > 0)
index 933fe3606201fd0cc6abe8fc8709b6e4bea4f99c..1fc176779dc097a87a78b79edf18e7b0e6833f09 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4362,
 /**/
     4361,
 /**/