]> granicus.if.org Git - vim/commitdiff
patch 8.2.3595: check for signed overflow might not work everywhere v8.2.3595
authorBram Moolenaar <Bram@vim.org>
Sun, 14 Nov 2021 14:05:18 +0000 (14:05 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 Nov 2021 14:05:18 +0000 (14:05 +0000)
Problem:    Check for signed overflow might not work everywhere.
Solution:   Limit to 32 bit int. (closes #9043, closes #9067)

src/getchar.c
src/version.c

index f2f38853b72b501781f9491f5013d7037eb4727c..a6644d8efa4411e326d193815bb8c345e2a411f1 100644 (file)
@@ -1001,6 +1001,8 @@ ins_typebuf(
     }
     else
     {
+       int extra;
+
        /*
         * Need to allocate a new buffer.
         * In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4)
@@ -1008,13 +1010,15 @@ ins_typebuf(
         * often.
         */
        newoff = MAXMAPLEN + 4;
-       newlen = typebuf.tb_len + addlen + newoff + 4 * (MAXMAPLEN + 4);
-       if (newlen < 0)             // string is getting too long
+       extra = addlen + newoff + 4 * (MAXMAPLEN + 4);
+       if (typebuf.tb_len > 2147483647 - extra)
        {
+           // string is getting too long for a 32 bit int
            emsg(_(e_toocompl));    // also calls flush_buffers
            setcursor();
            return FAIL;
        }
+       newlen = typebuf.tb_len + extra;
        s1 = alloc(newlen);
        if (s1 == NULL)             // out of memory
            return FAIL;
index 0374843d9484ac9ea2731ac630809ba31529c711..19014e67aef94d824d1bc7628a67aa519f98fd19 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3595,
 /**/
     3594,
 /**/