Vim 7.2c.002 Fixes Arbitrary Command Execution when Handling Tar Archives

From: Jan Minář <>
Subject: Vim 7.2c.002 Fixes Arbitrary Command Execution when Handling Tar Archives

Vim 7.2c.002 Fixes Arbitrary Command Execution when Handling Tar Archives


Product  : Vim -- Vi IMproved
Version  : Vim >= 7.0 (possibly older), fixed in 7.2c.002
          autoload/tar.vim version >= 9 (possibly older)
Impact   : Arbitrary code execution
Wherefrom: Local, remote
Original :

Vim update fixes a vulnerability that can lead to potential arbitrary
code execution when handling tar archives.  The fnameescape() function
does not sanitize input properly, which renders code that uses it
vulnerable.  Patch 7.2c.002 fixes the vulnerability.


 ``Vim is an almost compatible version of the UNIX editor Vi.  Many new
   features have been added: multi-level undo, syntax highlighting,
   command line history, on-line help, spell checking, filename
   completion, block operations, etc.''

               -- Vim README.txt

 ``When one edits a *.tar file, this plugin will handle displaying a
  contents page.  Select a file to edit by moving the cursor atop
  the desired file, then hit the <return> key.  After editing, one may
  also write to the file.''

               -- Tar File Interface (pi_tar.txt)


In statements such as the ones in ``$VIMRUNTIME/autoload/tar.vim'' on
lines 163, 308, 368, 407, and 419 (tar.vim version 20 (2008-07-30)):

   163    exe "r ".fnameescape(a:tarfile)
   308    exe "cd ".fnameescape(tmpdir)
   368    exe "w! ".fnameescape(fname)
   407     exe "e! ".fnameescape(tarfile)
   419   exe "cd ".fnameescape(curdir)

fnameescape() makes the untrusted file name safe as an argument to
``execute''.  However, the commands called by ``execute'' will in turn
each interpret the untrusted file name again.  This can be still used
for arbitrary command execution.  Another level of sanitizing/escaping
is needed in order to make the statements safe.


No exploit code is provided.

5. FIX

Fixed by patch 7.2c.002[2]: fnameescape() was updated to escape a
leading '+' and '>', and a single '-'.


[1] Collection of Vulnerabilities in Fully Patched Vim 7.1
[2] Patch 7.2c.002


This advisory is Copyright 2008 Jan Minar <>

Copying welcome, under the Creative Commons ``Attribution-Share Alike''

Code included herein, and accompanying this advisory, may be copied
according to the GNU General Public License version 2, or the Vim
license.  See the subdirectory ``licenses''.

Various portions of the accompanying code were written by various
parties.  Those parties may hold copyright, and those portions may be
copied according to their respective licenses.


2008-08-08 Sent to: <>,
2008-08-08 Patch 7.2c.002 released, fixing the vulnerability
2008-08-06 Reported to Vim maintainer

Copyright © 1995-2021 All rights reserved.