Skip to content

Commit c5f312a

Browse files
committed
patch 9.1.2148: [security]: Buffer overflow in netbeans interface
Problem: [security]: Buffer overflow in netbeans special_keys() handling Solution: Limit writing to max KEYBUFLEN bytes to prevent writing out of bounds. Github Advisory: GHSA-9w5c-hwr9-hc68 Signed-off-by: Christian Brabandt <[email protected]>
1 parent b8f58dd commit c5f312a

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

runtime/doc/version9.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52561,4 +52561,9 @@ Patch 9.1.2147
5256152561
Problem: Compile warning in strings.c
5256252562
Solution: Use const qualifier (John Marriott).
5256352563

52564+
Patch 9.1.2148
52565+
Problem: [security]: Buffer overflow in netbeans special_keys() handling
52566+
Solution: Limit writing to max KEYBUFLEN bytes to prevent writing out of
52567+
bounds.
52568+
5256452569
vim:tw=78:ts=8:noet:ft=help:norl:fdm=manual:nofoldenable

src/netbeans.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ special_keys(char_u *args)
23022302
if ((sep = strchr(tok, '-')) != NULL)
23032303
{
23042304
*sep = NUL;
2305-
while (*tok)
2305+
while (*tok && i + 2 < KEYBUFLEN)
23062306
{
23072307
switch (*tok)
23082308
{

src/testdir/test_netbeans.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def process_msgs(self, msgbuf):
112112
'startAtomic_Test' : '0:startAtomic!94\n',
113113
'endAtomic_Test' : '0:endAtomic!95\n',
114114
'AnnoScale_Test' : "".join(['2:defineAnnoType!60 ' + str(i) + ' "s' + str(i) + '" "x" "=>" blue none\n' for i in range(2, 26)]),
115-
'detach_Test' : '2:close!96\n1:close!97\nDETACH\n'
115+
'detach_Test' : '2:close!96\n1:close!97\nDETACH\n',
116+
'specialKeys_overflow_Test' : '0:specialKeys!200 "' + 'A'*80 + '-X"\n'
117+
116118
}
117119
# execute the specified test
118120
if cmd not in testmap:

src/testdir/test_netbeans.vim

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,58 @@ func Nb_bwipe_buffer(port)
958958
sleep 10m
959959
endfunc
960960

961+
func Nb_specialKeys_overflow(port)
962+
call delete("Xnetbeans")
963+
call writefile([], "Xnetbeans")
964+
965+
" Last line number in the Xnetbeans file. Used to verify the result of the
966+
" communication with the netbeans server
967+
let g:last = 0
968+
969+
" Establish the connection with the netbeans server
970+
exe 'nbstart :localhost:' .. a:port .. ':bunny'
971+
call WaitFor('len(ReadXnetbeans()) > (g:last + 2)')
972+
let l = ReadXnetbeans()
973+
call assert_equal(['AUTH bunny',
974+
\ '0:version=0 "2.5"',
975+
\ '0:startupDone=0'], l[-3:])
976+
let g:last += 3
977+
978+
" Open the command buffer to communicate with the server
979+
split Xcmdbuf
980+
let cmdbufnr = bufnr()
981+
call WaitFor('len(ReadXnetbeans()) > (g:last + 2)')
982+
let l = ReadXnetbeans()
983+
call assert_equal('0:fileOpened=0 "Xcmdbuf" T F',
984+
\ substitute(l[-3], '".*/', '"', ''))
985+
call assert_equal('send: 1:putBufferNumber!15 "Xcmdbuf"',
986+
\ substitute(l[-2], '".*/', '"', ''))
987+
call assert_equal('1:startDocumentListen!16', l[-1])
988+
let g:last += 3
989+
990+
" Keep the command buffer loaded for communication
991+
hide
992+
993+
sleep 1m
994+
995+
" Open the command buffer to communicate with the server
996+
split Xcmdbuf
997+
let cmdbufnr = bufnr()
998+
call appendbufline(cmdbufnr, '$', 'specialKeys_overflow_Test')
999+
call WaitFor('len(ReadXnetbeans()) >= (g:last + 6)')
1000+
call WaitForAssert({-> assert_match('send: 0:specialKeys!200 "A\{80}-X"',
1001+
\ ReadXnetbeans()[-1])})
1002+
1003+
" Verify that specialKeys test, still works after the previous junk
1004+
call appendbufline(cmdbufnr, '$', 'specialKeys_Test')
1005+
call WaitFor('len(ReadXnetbeans()) >= (g:last + 1)')
1006+
call WaitForAssert({-> assert_match('^send: 0:specialKeys!91 "F12 F13 C-F13"$',
1007+
\ ReadXnetbeans()[-1])})
1008+
let g:last += 1
1009+
1010+
sleep 10m
1011+
endfunc
1012+
9611013
" This test used to reference a buffer after it was freed leading to an ASAN
9621014
" error.
9631015
func Test_nb_bwipe_buffer()
@@ -967,4 +1019,9 @@ func Test_nb_bwipe_buffer()
9671019
nbclose
9681020
endfunc
9691021

1022+
" Verify that the specialKeys argument does not overflow
1023+
func Test_nb_specialKeys_overflow()
1024+
call s:run_server('Nb_specialKeys_overflow')
1025+
endfunc
1026+
9701027
" vim: shiftwidth=2 sts=2 expandtab

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+
2148,
737739
/**/
738740
2147,
739741
/**/

0 commit comments

Comments
 (0)