Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f7c0443

Browse files
CBL-Mariner-Botbhagyapathak
andauthoredJan 24, 2025··
[AUTO-CHERRYPICK] Fix CVE-2025-22134 in vim for 2.0 - branch main (#11973)
Co-authored-by: bhagyapathak <bhagyapathak@users.noreply.github.com>
1 parent 44055bc commit f7c0443

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed
 

‎SPECS/vim/CVE-2025-22134.patch

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
From c9a1e257f1630a0866447e53a564f7ff96a80ead Sat Jan 11 00:00:00 2025
2+
From: bhapathak <bhapathak@microsoft.com>
3+
Date: Wed, 15 Jan 2025 14:35:21 +0000
4+
Subject: [PATCH] Fix for CVE-2025-22134 - heap-buffer-overflow with visual mode
5+
6+
---
7+
diff --git a/src/arglist.c b/src/arglist.c
8+
index 8825c8e..4eec079 100644
9+
--- a/src/arglist.c
10+
+++ b/src/arglist.c
11+
@@ -1258,6 +1258,10 @@ do_arg_all(
12+
13+
tabpage_T *new_lu_tp = curtab;
14+
15+
+ // Stop Visual mode, the cursor and "VIsual" may very well be invalid after
16+
+ // switching to another buffer.
17+
+ reset_VIsual_and_resel();
18+
+
19+
// Try closing all windows that are not in the argument list.
20+
// Also close windows that are not full width;
21+
// When 'hidden' or "forceit" set the buffer becomes hidden.
22+
diff --git a/src/misc1.c b/src/misc1.c
23+
index 0898efb..bb87e22 100644
24+
--- a/src/misc1.c
25+
+++ b/src/misc1.c
26+
@@ -543,11 +543,15 @@ plines_m_win(win_T *wp, linenr_T first, linenr_T last, int max)
27+
gchar_pos(pos_T *pos)
28+
{
29+
char_u *ptr;
30+
-
31+
+ int ptrlen;
32+
+
33+
// When searching columns is sometimes put at the end of a line.
34+
if (pos->col == MAXCOL)
35+
return NUL;
36+
+ ptrlen = ml_get_len(pos->lnum);
37+
ptr = ml_get_pos(pos);
38+
+ if (pos->col > ptrlen)
39+
+ return NUL;
40+
if (has_mbyte)
41+
return (*mb_ptr2char)(ptr);
42+
return (int)*ptr;
43+
diff --git a/src/ops.c b/src/ops.c
44+
index eb8f64c..a1bd5b3 100644
45+
--- a/src/ops.c
46+
+++ b/src/ops.c
47+
@@ -2450,6 +2450,7 @@ charwise_block_prep(
48+
colnr_T startcol = 0, endcol = MAXCOL;
49+
colnr_T cs, ce;
50+
char_u *p;
51+
+ int plen = ml_get_len(lnum);
52+
53+
p = ml_get(lnum);
54+
bdp->startspaces = 0;
55+
@@ -2510,7 +2511,7 @@ charwise_block_prep(
56+
else
57+
bdp->textlen = endcol - startcol + inclusive;
58+
bdp->textcol = startcol;
59+
- bdp->textstart = p + startcol;
60+
+ bdp->textstart = startcol <= plen ? p + startcol : p;
61+
}
62+
63+
/*
64+
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
65+
index 3750ebf..9cfac32 100644
66+
--- a/src/testdir/test_visual.vim
67+
+++ b/src/testdir/test_visual.vim
68+
@@ -470,7 +470,7 @@ func Test_Visual_Block()
69+
\ "\t{",
70+
\ "\t}"], getline(1, '$'))
71+
72+
- close!
73+
+ bw!
74+
endfunc
75+
76+
" Test for 'p'ut in visual block mode
77+
@@ -1080,7 +1080,7 @@ func Test_star_register()
78+
79+
delmarks < >
80+
call assert_fails('*yank', 'E20:')
81+
- close!
82+
+ bw!
83+
endfunc
84+
85+
" Test for changing text in visual mode with 'exclusive' selection
86+
@@ -1096,7 +1096,7 @@ func Test_exclusive_selection()
87+
call assert_equal('l one', getline(1))
88+
set virtualedit&
89+
set selection&
90+
- close!
91+
+ bw!
92+
endfunc
93+
94+
" Test for starting linewise visual with a count.
95+
@@ -1165,6 +1165,24 @@ func Test_visual_put_in_block()
96+
bwipe!
97+
endfunc
98+
99+
+" the following caused a Heap-Overflow, because Vim was accessing outside of a
100+
+" line end
101+
+func Test_visual_pos_buffer_heap_overflow()
102+
+ set virtualedit=all
103+
+ args Xa Xb
104+
+ all
105+
+ call setline(1, ['', '', ''])
106+
+ call cursor(3, 1)
107+
+ wincmd w
108+
+ call setline(1, 'foobar')
109+
+ normal! $lv0
110+
+ all
111+
+ call setreg('"', 'baz')
112+
+ normal! [P
113+
+ set virtualedit=
114+
+ bw! Xa Xb
115+
+endfunc
116+
+
117+
func Test_visual_put_in_block_using_zp()
118+
new
119+
" paste using zP

‎SPECS/vim/vim.spec

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Summary: Text editor
33
Name: vim
44
Version: 9.1.0791
5-
Release: 1%{?dist}
5+
Release: 2%{?dist}
66
License: Vim
77
Vendor: Microsoft Corporation
88
Distribution: Mariner
99
Group: Applications/Editors
1010
URL: https://www.vim.org
1111
Source0: https://github.com/%{name}/%{name}/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
12+
Patch0: CVE-2025-22134.patch
1213

1314
BuildRequires: ncurses-devel
1415
BuildRequires: python3-devel
@@ -199,6 +200,9 @@ fi
199200
%{_bindir}/vimdiff
200201

201202
%changelog
203+
* Thu Jan 16 2025 Bhagyashri Pathak <bhapathak@microsoft.com> - 9.1.0791-2
204+
- Patch for fixing CVE-2025-22134
205+
202206
* Thu Oct 17 2024 Nick Samson <nisamson@microsoft.com> - 9.1.0791-1
203207
- Upgrade to 9.1.0791 to fix CVE-2024-47814, CVE-2024-43802
204208
- Added language configurations for Amharic and Hungarian

0 commit comments

Comments
 (0)
Please sign in to comment.