Use After Free in vim/vim
Description
Use-after-free in Vim's do_window function when searching for a defined word triggers freed memory access, fixed in 8.2.4979.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Use-after-free in Vim's do_window function when searching for a defined word triggers freed memory access, fixed in 8.2.4979.
Vulnerability
A use-after-free vulnerability exists in the do_window function of the Vim source code prior to version 8.2.4979 [1]. When Vim executes a command that triggers "#define" search (CTRL-W_#), the code in find_ident_under_cursor returns a pointer to a line buffer. If the original line is modified during subsequent operations, the pointer becomes invalid, and using it without copying leads to accessing freed memory [1]. This affects all Vim installations using the vulnerable versions.
Exploitation
An attacker requires the ability to open a specially crafted file in Vim and then cause the user to execute the "CTRL-W #" command (or another operation that invokes do_window with FIND_DEFINE) [1]. The attacker must also craft a file that triggers a line flush or modification after find_ident_under_cursor reads the identifier, such as through autocmds or specific buffer manipulations [1]. The provided test scenario uses setline to modify the buffer, sil norm o0 to add a line, and sil! norm CTRL-W # to trigger the search, which then accesses the freed pointer [1].
Impact
Successful exploitation allows an attacker to read or write freed heap memory by controlling the contents of the freed buffer [1]. The consequence can range from an application crash (denial of service) to potentially arbitrary code execution, depending on the heap state. The vulnerability has a CVSS score of 7.8 (High) and can compromise the confidentiality, integrity, and availability of the system [2][3].
Mitigation
Vim fixed this issue in patch 8.2.4979, released on 2022-05-19 [1]. Gentoo GLSA 202208-32 and 202305-16 recommend upgrading Vim to version 9.0.0060 or later (and subsequently 9.0.1157 for continued protection) [2][3]. Users should update their Vim installation to a patched version. There is no known workaround for unpatched versions [2][3].
AI Insight generated on May 27, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected products
38- osv-coords36 versionspkg:rpm/opensuse/vim&distro=openSUSE%20Leap%2015.3pkg:rpm/opensuse/vim&distro=openSUSE%20Leap%2015.4pkg:rpm/opensuse/vim&distro=openSUSE%20Tumbleweedpkg:rpm/suse/vim&distro=SUSE%20Enterprise%20Storage%206pkg:rpm/suse/vim&distro=SUSE%20Enterprise%20Storage%207pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP1-ESPOSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP1-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP2-ESPOSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015%20SP2-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015-ESPOSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20High%20Performance%20Computing%2015-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Micro%205.1pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Micro%205.2pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP3pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP4pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Desktop%20Applications%2015%20SP3pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Desktop%20Applications%2015%20SP4pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP2-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP3-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP4-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP5pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP1-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP1-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP2-BCLpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015%20SP2-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%2015-LTSSpkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2012%20SP4pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2012%20SP5pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2015pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2015%20SP1pkg:rpm/suse/vim&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2015%20SP2pkg:rpm/suse/vim&distro=SUSE%20Manager%20Proxy%204.1pkg:rpm/suse/vim&distro=SUSE%20Manager%20Retail%20Branch%20Server%204.1pkg:rpm/suse/vim&distro=SUSE%20Manager%20Server%204.1pkg:rpm/suse/vim&distro=SUSE%20OpenStack%20Cloud%209pkg:rpm/suse/vim&distro=SUSE%20OpenStack%20Cloud%20Crowbar%209
< 8.2.5038-150000.5.21.1+ 35 more
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 9.0.0453-2.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 8.2.5038-150000.5.21.1
- (no CPE)range: < 9.0.0814-17.9.1
- (no CPE)range: < 9.0.0814-17.9.1
Patches
0No patches discovered yet.
Vulnerability mechanics
Root cause
"Use-after-free: `do_window()` passes a pointer into a line buffer to `find_pattern_in_path()` without copying it first, and the line can be freed before the pointer is used."
Attack vector
An attacker can trigger a use-after-free by crafting a buffer where a line is modified (flushed) while `do_window()` holds a pointer into it. The reproduction uses `setline()` to create specific content, then executes `CTRL-W_CTRL-D` (normal mode command ``) which invokes the vulnerable code path. When the line is freed and reallocated, the stale pointer `ptr` is dereferenced in `find_pattern_in_path()`, causing a use-after-free [ref_id=1].
Affected code
The vulnerability is in the `do_window()` function in Vim's source code. The function calls `find_ident_under_cursor()` which returns a pointer `ptr` into the current line, then passes that pointer directly to `find_pattern_in_path()`. If the line is changed (flushed) between these calls, the pointer becomes dangling.
What the fix does
The patch [ref_id=1] makes a copy of the string returned by `find_ident_under_cursor()` using `vim_strnsave()` before passing it to `find_pattern_in_path()`. This ensures the pointer remains valid even if the underlying line is freed. The copy is freed with `vim_free()` after `find_pattern_in_path()` returns. The patch also adds a test case `Test_define_search()` that reproduces the crash scenario.
Preconditions
- inputThe attacker must be able to supply a buffer with specific line content (e.g., via setline()) that triggers a line flush during the CTRL-W_CTRL-D command.
- authThe attacker must be able to execute normal mode commands in Vim (e.g., via silent norm).
Reproduction
The test case in the patch [ref_id=1] reproduces the issue: create a new buffer, set lines to `['first line', '', '#define something 0']`, enter `0` on a new line with `sil norm o0`, then execute `sil! norm ` (CTRL-W CTRL-D). This triggers the use-after-free.
Generated on May 27, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
4- security.gentoo.org/glsa/202208-32mitrevendor-advisory
- security.gentoo.org/glsa/202305-16mitrevendor-advisory
- github.com/vim/vim/commit/28d032cc688ccfda18c5bbcab8b50aba6e18cde5mitre
- huntr.dev/bounties/f6739b58-49f9-4056-a843-bf76bbc1253emitre
News mentions
0No linked articles in our index yet.