Summary
Vim's C omni-completion script mishandles tag metadata by interpolating it directly into a :vimgrep pattern that is executed without escaping.
If a project's tags file contains a crafted typeref or typename field and a user opens a hostile C file and triggers omni-completion, arbitrary Ex commands can be executed with the user's privileges.
Affected context
This vulnerability appears in Vim environments that:
- Use the built-in C omni-completion feature
- Load tag metadata from project tags files (e.g., ctags output)
- Trust typeref: or typename: extension fields without sanitization
It becomes relevant when users open C source files from potentially untrusted projects and rely on omni-completion, allowing crafted tag entries to influence editor commands.
Exploit preconditions
- Attack surface: Local editor session running Vim with C omni-completion enabled
- Required access: Ability to create or modify the project tags file consumed by Vim (e.g., via ctags generation or repository control)
- Trigger point: Invoking C omni-completion on a C buffer that uses tags containing malicious typeref:/typename: fields
- Why exploitation is possible: The omni-completion script interpolates tag extension fields directly into a :vimgrep pattern, which is passed through :execute; since :vimgrep treats the bar character as a command separator, an attacker can terminate the search and append arbitrary Ex commands.
Why this happens
The underlying issue is a code injection pattern where untrusted data is composed into a command string that is later interpreted by a powerful command engine.
In this case, tag extension fields such as typeref: and typename: are assumed to be benign search tokens and embedded into a :vimgrep pattern without escaping special characters or enforcing a strict grammar.
Because the constructed pattern is executed via :execute, any embedded command separators can break out of the search context and introduce arbitrary Ex commands, mapping directly to CWE-94: Code Injection through misused metacharacters and lack of input validation.
Potential impact
- Execution of arbitrary Ex commands within the user's Vim session
- Modification or deletion of files accessible to the editing user
- Insertion of malicious content into source files or configuration files
- Potential chaining with other local tools or scripts invoked from Vim
- Disruption of the development environment and tampering with project artifacts
General mitigation guidance
Effective mitigation focuses on reducing trust in external metadata and preventing command construction from unsanitized input.
Common defensive patterns include:
- Escaping or quoting any user-controlled or file-derived data before embedding it in command strings
- Using structured APIs for search and completion that separate data from command syntax rather than assembling raw Ex commands
- Limiting the completion scripts' ability to invoke generic :execute with dynamically built strings
- Encouraging workflows where tags files from untrusted sources are treated with caution and not automatically consumed
- Running editors with reduced privileges relative to system-wide resources and sensitive files, so that accidental command execution has limited impact
How teams detect issues like this
Detection generally relies on reviewing script code and configuration for insecure command construction patterns.
Useful approaches include:
- Static analysis or linting rules that flag :execute usage with concatenated strings derived from tags or other external metadata
- Manual review of Vimscript and editor plugins for interpolation of untrusted values into :vimgrep, :grep, or other Ex commands
- Policy checks in version control to scrutinize changes to completion scripts and tag handling logic
- Optional use of security-focused scanners or automated review tools that recognize CWE-94 patterns in scripting languages

