vim uses ./$TMPDIR (literally, not expanded) as temporary directory

Bug #184719 reported by Malcolm Scott
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
vim (Ubuntu)
Confirmed
Undecided
Unassigned
Nominated for Intrepid by Malcolm Scott
Nominated for Karmic by Malcolm Scott
Nominated for Lucid by Malcolm Scott

Bug Description

Binary package hint: vim

If the TMPDIR environment variable is *not* set, vim will attempt to create temporary files in ./$TMPDIR (a literal directory name containing a dollar sign, not an environment variable expansion). It should instead try /tmp if TMPDIR is not set.

Implications:
1. If ./$TMPDIR exists, vim may issue an error message on startup (see below);
2. If vim is started in a directory such as an autofs mountpoint in which any requested directory will exist, vim hangs forever trying to create temporary directories waiting until it finds one that does not exist.

This latter case, although quite rare, is the one which alerted me to the problem; I observed the following strace excerpt:

stat64("$TMPDIR", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
getpid() = 15010
time(NULL) = 1200881832
umask(077) = 02
mkdir("$TMPDIR/v896842", 0700) = -1 EEXIST (File exists)
umask(02) = 077
umask(077) = 02
mkdir("$TMPDIR/v896842v896843", 0700) = -1 EEXIST (File exists)
umask(02) = 077
umask(077) = 02
mkdir("$TMPDIR/v896842v896843v896844", 0700) = -1 EEXIST (File exists)
umask(02) = 077
umask(077) = 02
mkdir("$TMPDIR/v896842v896843v896844v896845", 0700 <unfinished ...>
...and so on, indefinitely.

I have reproduced the problem in a more conventional directory:

mas90@callisto:~$ mkdir \$TMPDIR
mas90@callisto:~$ vim
Error detected while processing /usr/share/vim/vim71/debian.vim:
line 58:
E484: Cannot open file /home/mas90/$TMPDIR/v904285/0
Press ENTER or type command to continue

From a brief look through the source, I believe that this is due to a fault in the expand_env_esc function in src/misc1.c: as far as I can tell, when expanding a string containing "$FOO" when environment variable FOO is unset or empty, "$FOO" will remain in the string. (The call to vim_getenv on line 3609 will return NULL if the variable requested is unset/empty, and NULL in *var will cause the conditional starting on line 3739 to fail and hence $FOO will not be replaced in the string.)

expand_env_esc is called via expand_env from src/fileio.c:6762, which iterates through the tempdirs array until it finds one which exists; tempdirs is initialised from the macro TEMPDIRNAMES, which is defined (on UNIX) to be "$TMPDIR", "/tmp", ".", "$HOME".

I'm running vim 1:7.1-056+2ubuntu2 from gutsy.

Changed in vim:
status: New → Confirmed
Revision history for this message
James McCoy (jamessan) wrote :

Your second point, about Vim hanging trying to create temporary directories, is fixed as of patch 7.2.294 and will be available once 2:7.2.330-1 is synced from Debian.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.