]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0293: :packadd may lead to heap-buffer-overflow v9.2.0293
authorzeertzjq <zeertzjq@outlook.com>
Sat, 4 Apr 2026 08:32:33 +0000 (08:32 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 4 Apr 2026 08:32:33 +0000 (08:32 +0000)
Problem:  :packadd may lead to heap-buffer-overflow when all entries in
          'runtimepath' have the same length (after 9.2.0291).
Solution: Check for comma after current entry properly (zeertzjq).

related: #19854
closes:  #19911

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/scriptfile.c
src/testdir/test_packadd.vim
src/version.c

index 6df5781a7305a411a2299c3abe3045ff6b69c0d7..df90fe77117fc64dfc377362a748ee9714a129bf 100644 (file)
@@ -885,7 +885,7 @@ add_pack_dir_to_rtp(char_u *fname)
        buf.length = (size_t)copy_option_part(&entry, buf.string, MAXPATHL, ",");
 
        // keep track of p_rtp length as we go to make the STRLEN() below have less work to do
-       p_rtp_len += (*(p_rtp + buf.length) == ',') ? buf.length + 1 : buf.length;
+       p_rtp_len += (*(cur_entry + buf.length) == ',') ? buf.length + 1 : buf.length;
 
        if ((p = (char_u *)strstr((char *)buf.string, "after")) != NULL
                && p > buf.string
index cd7126a9dbadaf95f395daacd5120329cbbd8bf8..6a368762a92c6033940a4bfe3c31cbb0c8968803 100644 (file)
@@ -26,6 +26,13 @@ func Test_packadd()
   " plugdir should be inserted before plugdir/after
   call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp)
 
+  " This used to cause heep-buffer-overflow
+  " All existing entries in 'rtp' have the same length here
+  let &rtp = 'Xfoodir,Xbardir,Xbazdir'
+  packadd mytest
+  " plugdir should be inserted after the existing directories
+  call assert_match('^Xfoodir,Xbardir,Xbazdir,' .. s:plugdir .. ',', &rtp)
+
   set rtp&
   let rtp = &rtp
   filetype on
index c9db272bbbc66b99551cf1f5a67826d6c81b0146..50474f4ac56da5d86011fcd43c6eaa4eebf3c49b 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    293,
 /**/
     292,
 /**/