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

Use After Free in vim/vim

CVE-2022-3016

Description

A use-after-free vulnerability in Vim before 9.0.0286 can be triggered when a location list is modified by an autocommand during a quickfix/location list jump operation.

AI Insight

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

A use-after-free vulnerability in Vim before 9.0.0286 can be triggered when a location list is modified by an autocommand during a quickfix/location list jump operation.

Vulnerability

CVE-2022-3016 is a use-after-free vulnerability in Vim, affecting versions prior to 9.0.0286. The bug resides in the quickfix/location list jump code, specifically in the functions qf_jump_edit_buffer and qf_jump_open_window. When Vim opens a buffer during a quickfix or location list jump, an autocommand can modify the list, causing Vim to use freed memory. The patch introduces a new return value QF_ABORT to handle this case and avoid accessing freed memory [1].

Exploitation

An attacker must first craft a Vim session where an autocommand is set to modify the quickfix or location list when a buffer is opened. The attacker then needs to trigger a jump to an entry in that list, for example by using the :cnext or :lnext commands. When Vim executes the jump, the autocommand runs and frees the list while Vim still holds a reference to it, leading to a use-after-free condition. No authentication or special network position is required if the attacker can supply a malicious Vim script or file that triggers the autocommand [1].

Impact

Successful exploitation can lead to a denial of service (crash) or potentially arbitrary code execution in the context of the Vim process, depending on how the freed memory is reused. The vulnerability has a CVSS score of 9.8 (critical), indicating high impact on confidentiality, integrity, and availability. The Gentoo advisory lists this as part of a set of vulnerabilities that could result in denial of service [3].

Mitigation

The vulnerability is fixed in Vim version 9.0.0286. Users should upgrade to this version or later. The patch [1] addresses the use-after-free by checking the list validity and returning a new status code. Gentoo recommends updating to >=app-editors/vim-9.0.1157 or >=app-editors/gvim-9.0.1157 [3]. No known workaround exists for unpatched versions. The CVE is not listed in the CISA Known Exploited Vulnerabilities (KEV) catalog.

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

39

Patches

0

No patches discovered yet.

Vulnerability mechanics

Root cause

"Use-after-free in quickfix/location list jump functions when an autocommand frees the list, because the caller continues using pointers to freed memory."

Attack vector

An attacker crafts a file that, when opened via a quickfix or location list jump, triggers an autocommand (e.g., `BufReadPost`, `FileType`) that frees or modifies the quickfix/location list data structure. Because the jump functions previously returned `NOTDONE` or `FAIL` without invalidating the `qi` and `qf_ptr` pointers, the caller `qf_jump_newwin` could continue using those freed pointers, leading to a use-after-free condition [ref_id=1]. The attacker needs to supply a file and a corresponding quickfix/location list that causes Vim to execute the vulnerable code path.

Affected code

The vulnerability is in the quickfix/location list jump functions within `src/quickfix.c`. The patch modifies `qf_jump_edit_buffer`, `qf_jump_open_window`, `qf_jump_newwin`, and related functions to return a new `QF_ABORT` value (enum constant 6) instead of `NOTDONE` or `FAIL` when an autocommand frees or modifies the quickfix/location list during buffer opening [ref_id=1].

What the fix does

The patch introduces a new enum value `QF_ABORT` (6) to distinguish the case where an autocommand freed or modified the quickfix/location list from other failure states. Functions `qf_jump_edit_buffer`, `qf_jump_open_window`, and `qf_jump_to_buffer` now return `QF_ABORT` instead of `NOTDONE` or `FAIL` when the list is invalidated. In `qf_jump_newwin`, the callers check for `QF_ABORT` and explicitly set `qi = NULL` and `qf_ptr = NULL` before jumping to `theend`, preventing any subsequent use of the freed pointers [ref_id=1].

Preconditions

  • inputThe attacker must supply a file that, when opened via a quickfix/location list jump, triggers an autocommand that frees or modifies the quickfix/location list.
  • inputThe victim must open the crafted file using a quickfix or location list jump (e.g., via :cnext, :lnext, or similar commands).

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

References

4

News mentions

0

No linked articles in our index yet.