]> granicus.if.org Git - vim/commitdiff
patch 8.2.3403: memory leak for :retab with invalid argument v8.2.3403
authorBram Moolenaar <Bram@vim.org>
Sat, 4 Sep 2021 19:20:41 +0000 (21:20 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 4 Sep 2021 19:20:41 +0000 (21:20 +0200)
Problem:    Memory leak for :retab with invalid argument.
Solution:   Free the memory.  Make error messages consistent.

src/indent.c
src/version.c

index cd03f25d25842e86cdce8fe1fa0ddfb1a72303f5..51af4df06babce4eb5a6ac6da72ca448dc6a51c0 100644 (file)
@@ -70,9 +70,12 @@ tabstop_set(char_u *var, int **array)
     {
        int n = atoi((char *)cp);
 
+       // Catch negative values, overflow and ridiculous big values.
        if (n < 0 || n > 9999)
        {
            semsg(_(e_invarg2), cp);
+           vim_free(*array);
+           *array = NULL;
            return FAIL;
        }
        (*array)[t++] = n;
@@ -1615,12 +1618,18 @@ ex_retab(exarg_T *eap)
     else
        new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str);
 #else
-    new_ts = getdigits(&(eap->arg));
-    if (new_ts < 0)
+    ptr = eap->arg;
+    new_ts = getdigits(&ptr);
+    if (new_ts < 0 && *eap->arg == '-')
     {
        emsg(_(e_positive));
        return;
     }
+    if (new_ts < 0 || new_ts > 9999)
+    {
+       semsg(_(e_invarg2), eap->arg);
+       return;
+    }
     if (new_ts == 0)
        new_ts = curbuf->b_p_ts;
 #endif
index a5e931cfad1fd8d694c63f70473c6e628ae8eb29..97467aab99206058526bad55f95f1a0eff685fa7 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3403,
 /**/
     3402,
 /**/