VYPR
Unrated severityNVD Advisory· Published Oct 15, 2021· Updated Aug 3, 2024

Heap-based Buffer Overflow in vim/vim

CVE-2021-3875

Description

A heap-based buffer overflow in vim's get_address() function allows a crash or potential memory corruption when a crafted search command with an invalid range is used.

AI Insight

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

A heap-based buffer overflow in vim's get_address() function allows a crash or potential memory corruption when a crafted search command with an invalid range is used.

Vulnerability

CVE-2021-3875 is a heap-based buffer overflow vulnerability in the get_address() function of vim, specifically affecting versions prior to patch 8.2.3489 [2]. The flaw occurs when a search command (like / or ?) follows another address and the line number (lnum) is set to a value greater than the current buffer's line count (ml_line_count), which can result in an out-of-bounds write to heap memory [2]. The vulnerability is triggered by a specially crafted search range input, such as \%.v followed by 5/ and c as shown in the test case added in the fix [2].

Exploitation

To exploit this vulnerability, an attacker must convince a victim to open a malicious file or execute a crafted command sequence in vim. The attack requires no special privileges; any user with the ability to open a file in vim could trigger the bug. By crafting a file that contains a search pattern with an invalid line number range (e.g., lnum set beyond the buffer's line count), the attacker can cause the get_address() function to use an unsanitized line number, leading to heap corruption [2]. No user interaction beyond opening the file or executing the malicious command is required.

Impact

Successful exploitation of the heap-based buffer overflow can lead to a crash of vim or potentially to arbitrary code execution, depending on the heap layout and memory protections. The impact is primarily a denial of service (crash) or memory corruption. In environments where vim is used to edit privileged files (e.g., system configuration files with elevated privileges), exploitation could lead to privilege escalation, although this is not a typical scenario [1].

Mitigation

The vulnerability has been patched in vim version 8.2.3489, released on 2021-10-15 [2]. Users should upgrade to the latest stable release of vim (8.2.3489 or later). No workaround is available for unpatched versions. The vulnerability is not listed in the Known Exploited Vulnerabilities (KEV) catalog. Fedora and other distributions have announced patches via their package update channels [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

37

Patches

0

No patches discovered yet.

Vulnerability mechanics

Root cause

"Missing bounds check on the line number in `get_address()` allows setting the cursor to a value exceeding the buffer's line count, causing a heap-based buffer overflow."

Attack vector

An attacker can craft a Vim script file (e.g., a `.vim` file) containing a search command with an invalid range, such as `5/` after a pattern like `/\.v`. When Vim sources this file, the `get_address()` function sets the cursor line number to a value that exceeds the number of lines in the buffer, leading to a heap-based buffer overflow [ref_id=1]. No authentication or special privileges are required beyond opening the malicious file.

Affected code

The heap-based buffer overflow occurs in `get_address()` in `src/eval.c`. The patch adds a bounds check on `lnum` before assigning it to `curwin->w_cursor.lnum`, ensuring it does not exceed `curbuf->b_ml.ml_line_count`.

What the fix does

The patch adds two guards in `get_address()`: first, it checks that `lnum > 0` before using it, and second, it clamps `lnum` to `curbuf->b_ml.ml_line_count` if it exceeds the buffer's line count. This prevents the cursor from being set to an out-of-bounds line number, which previously caused a heap-buffer-overflow when Vim later accessed the line data [ref_id=1].

Preconditions

  • inputThe attacker must supply a Vim script file that triggers a search with an invalid range (e.g., a line number larger than the buffer's line count).
  • inputThe user must open or source the malicious file in Vim.

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

References

6

News mentions

0

No linked articles in our index yet.