VYPR
Unrated severityNVD Advisory· Published May 17, 2022· Updated Aug 3, 2024

Classic Buffer Overflow in vim/vim

CVE-2022-1735

Description

A classic buffer overflow in Vim before 8.2.4969 allows arbitrary code execution via a crafted file when Visual mode is active.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

A classic buffer overflow in Vim before 8.2.4969 allows arbitrary code execution via a crafted file when Visual mode is active.

Vulnerability

A classic buffer overflow exists in Vim versions prior to [8.2.4969] [2]. The flaw resides in the changed_common() and stop_insert() functions, where the Visual mode selection position (VIsual) is not properly validated after text changes [2]. When Visual mode is active and a modification occurs, the code can access memory outside the allocated buffer boundary, leading to a classic buffer overflow condition [2]. The issue is triggered specifically when VIsual_active is true and the visual selection coordinates become invalid after editing operations [2].

Exploitation

An attacker can exploit this vulnerability by convincing a user to open a specially crafted file in Vim or gVim with Visual mode enabled [2]. No authentication or network access is required beyond delivering the malicious file (e.g., via email attachment, web download, or repository) [2]. When the user performs an edit operation (such as deleting or replacing text) while Visual mode is active, the check_visual_pos() function was either missing or incomplete, causing the buffer overflow to occur [2]. The attacker does not need any prior access or special privileges on the target system.

Impact

Successful exploitation can lead to arbitrary code execution in the context of the Vim process [1]. On macOS Ventura 13, Apple's advisory notes that “processing a maliciously crafted image may lead to arbitrary code execution” [1], though the vulnerability is general to any editor session [2]. The attacker gains the same privileges as the user running Vim, which may allow full compromise of the user's files and system [1,2].

Mitigation

The fix was released in Vim version 8.2.4969 [2]. Users should upgrade to Vim 9.0.0060 or later as recommended by Gentoo [3], or to Vim 9.0.1157 per later advisories [4]. Apple included the fix in macOS Ventura 13 (released October 24, 2022) [1]. No workaround is available if upgrading is not possible [3,4].

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

Patches

0

No patches discovered yet.

Vulnerability mechanics

Root cause

"Missing validation of the Visual selection position after text changes can leave VIsual pointing beyond valid buffer memory."

Attack vector

An attacker can craft a file that, when opened in Vim, causes the user to perform a Visual mode operation (e.g., a visual block substitute) that triggers a text change. If the change reduces the number of lines or shortens a line, the stored `VIsual` position (line number and column) can become invalid — pointing beyond the end of the buffer or beyond the end of a line. When Vim later uses this stale position, it reads out-of-bounds memory, leading to a classic buffer overflow [ref_id=1].

Affected code

The vulnerability is in Vim's handling of the Visual mode position (`VIsual`) after text changes. The patch modifies `changed_common()` and `stop_insert()` in `src/change.c` to call a new `check_visual_pos()` function instead of performing only a partial bounds check. The new function is defined in `src/cursor.c` and declared in `src/proto/cursor.pro`.

What the fix does

The patch introduces `check_visual_pos()` in `src/cursor.c`, which validates both the line number (clamping to `ml_line_count`) and the column (clamping to the line length). This function is called from `changed_common()` and `stop_insert()` whenever `VIsual_active` is true, replacing the earlier incomplete check that only handled the case where `VIsual.lnum == curwin->w_cursor.lnum` and only corrected the column, not the line number [ref_id=1]. The new check also handles the case where the Visual selection's line number itself is now past the last line, which the old code did not address.

Preconditions

  • inputThe victim must open a crafted file in Vim
  • inputThe victim must perform a Visual mode operation that triggers a text change (e.g., substitute)

Generated on May 27, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

7

News mentions

0

No linked articles in our index yet.