Skip to content

Commit bc182ae

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.2.0293: :packadd may lead to heap-buffer-overflow
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>
1 parent a9d01da commit bc182ae

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/scriptfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ add_pack_dir_to_rtp(char_u *fname)
885885
buf.length = (size_t)copy_option_part(&entry, buf.string, MAXPATHL, ",");
886886

887887
// keep track of p_rtp length as we go to make the STRLEN() below have less work to do
888-
p_rtp_len += (*(p_rtp + buf.length) == ',') ? buf.length + 1 : buf.length;
888+
p_rtp_len += (*(cur_entry + buf.length) == ',') ? buf.length + 1 : buf.length;
889889

890890
if ((p = (char_u *)strstr((char *)buf.string, "after")) != NULL
891891
&& p > buf.string

src/testdir/test_packadd.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ func Test_packadd()
2626
" plugdir should be inserted before plugdir/after
2727
call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp)
2828

29+
" This used to cause heep-buffer-overflow
30+
" All existing entries in 'rtp' have the same length here
31+
let &rtp = 'Xfoodir,Xbardir,Xbazdir'
32+
packadd mytest
33+
" plugdir should be inserted after the existing directories
34+
call assert_match('^Xfoodir,Xbardir,Xbazdir,' .. s:plugdir .. ',', &rtp)
35+
2936
set rtp&
3037
let rtp = &rtp
3138
filetype on

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
293,
737739
/**/
738740
292,
739741
/**/

0 commit comments

Comments
 (0)