Skip to content

Commit 8ea5f27

Browse files
mattnchrisbra
authored andcommitted
patch 9.2.0266: typeahead buffer overflow during mouse drag event
Problem: typeahead buffer overflow during mouse drag event Solution: Change the guard from 5 to 10 to account for the worst case (Yasuhiro Matsumoto). The typeahead buffer guard in mch_inchar() only reserved 5 bytes per iteration, but a mouse event writes up to 7 bytes (3 header + 4 coordinates) and a scroll event with modifiers writes up to 10 bytes (3 modifier + 3 scroll + 4 coordinates). During fast mouse dragging, 3+ events could queue up and overflow the 20-byte buffer, corrupting adjacent static variables and causing garbage bytes (including Ctrl-Z) to be fed into the input stream, which triggered nv_suspend/ex_stop. closes: #19851 Signed-off-by: Yasuhiro Matsumoto <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent f896627 commit 8ea5f27

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/os_win32.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,10 +2424,11 @@ mch_inchar(
24242424
# endif
24252425

24262426
// Keep looping until there is something in the typeahead buffer and more
2427-
// to get and still room in the buffer (up to two bytes for a char and
2428-
// three bytes for a modifier).
2427+
// to get and still room in the buffer. A mouse event uses up to
2428+
// 10 bytes: 3 (modifier) + 3 (scroll event) + 4 (coordinates), and a
2429+
// keyboard input uses up to 7 bytes: 3 (modifier) + 4 (UTF-8 char).
24292430
while ((typeaheadlen == 0 || WaitForChar(0L, FALSE))
2430-
&& typeaheadlen + 5 + TYPEAHEADSPACE <= TYPEAHEADLEN)
2431+
&& typeaheadlen + 10 + TYPEAHEADSPACE <= TYPEAHEADLEN)
24312432
{
24322433
if (typebuf_changed(tb_change_cnt))
24332434
{

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+
266,
737739
/**/
738740
265,
739741
/**/

0 commit comments

Comments
 (0)