blob: 71479e0becd458a13b3b0fdeab42c9b0cb5921f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
From: Markus Koschany <apo@debian.org>
Date: Mon, 31 Oct 2022 20:40:05 +0100
Subject: CVE-2022-1720
Origin: https://github.com/vim/vim/commit/395bd1f6d3edc9f7edb5d1f2d7deaf5a9e3ab93c
---
src/normal.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
--- a/src/normal.c
+++ b/src/normal.c
@@ -5777,9 +5777,17 @@ get_visual_text(
*pp = ml_get_pos(&VIsual);
*lenp = curwin->w_cursor.col - VIsual.col + 1;
}
- if (has_mbyte)
- /* Correct the length to include the whole last character. */
- *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
+ if (*lenp > 0)
+ {
+ if (has_mbyte)
+ // Correct the length to include all bytes of the last
+ // character.
+ *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
+ else if ((*pp)[*lenp - 1] == NUL)
+ // Do not include a trailing NUL.
+ *lenp -= 1;
+ }
+
}
reset_VIsual_and_resel();
return OK;
|