]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0487: viminfo: possible signed int overflow in register array v9.2.0487
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Fri, 15 May 2026 16:44:46 +0000 (16:44 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 15 May 2026 16:44:46 +0000 (16:44 +0000)
Problem:  viminfo: possible signed int overflow in register array growth
Solution: Cast to size_t (Yasuhiro Matsumoto)

The expression `limit * 2 * sizeof(string_T)` in read_viminfo_register()
multiplies in int and overflows once limit exceeds INT_MAX/2. Cast to
size_t first so the size computation stays unsigned. Defensive only;
reaching this path requires registers consuming many gigabytes.

closes: #20207

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/version.c
src/viminfo.c

index 046cc83425f1495e4589187d7441be83cd17de7c..0714ec1ac093e0e557d5a5bde32f48ab9e8f4ae4 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    487,
 /**/
     486,
 /**/
index d05900544a8b5f8eb295407d79abecc976331857..bb84726c8f99595be511ed1b6ab39f8303d69982 100644 (file)
@@ -1706,7 +1706,7 @@ read_viminfo_register(vir_T *virp, int force)
            if (size == limit)
            {
                string_T *new_array = (string_T *)
-                                          alloc(limit * 2 * sizeof(string_T));
+                                   alloc((size_t)limit * 2 * sizeof(string_T));
 
                if (new_array == NULL)
                {