Matt Wozniski wrote:

> src/fileio.c : vim_tempname() contains these lines:
> 
>     if (GetTempFileName(szTempFile, buf4, 0, itmp) == 0)
>       return NULL;
>     /* GetTempFileName() will create the file, we don't want that */
>     (void)DeleteFile(itmp);
> 
> Is this really right?  Is there any reason to call DeleteFile() here?
> On a quick glance, it seems that everyone who gets a name back is just
> doing an mch_open(tempname, "w") on it, which doesn't care whether or
> not the file exists already.
> 
> I ask because this seems to be causing a race condition:
> GetTempFileName() checks if a file exists, finds a name that doesn't
> exist, creates it, and returns the name back to the caller.  It
> creates it so that future calls to GetTempFileName() won't choose the
> same file, since it now exists.  But, deleting it before being done
> with it introduces a race condition: vim calls GetTempFileName(), then
> DeleteFile(), then another process calls GetTempFileName(), and now
> vim has the path to a file that didn't exist when it asked for a
> unique, non-existant file, but exists now, and is no longer safe for
> vim to use.

I have never seen the situation that another process (or Vim itself)
gets the same file name.  I don't have access to a windows system right
now, but if I remember correctly the names look like a random sequence
of characters.

For Unix we create our own directory, which is a safe way to avoid
others to take over our file unexpectedly.

Not all code that invokes vim_tempname() starts writing to the file.
Most notable is the tempname() function.

Changing this behavior will not be easy, so you will have to come up
with some kind of proof that the current mechanism may fail.

-- 
>From "know your smileys":
 <|-) Chinese
 <|-( Chinese and doesn't like these kind of jokes

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui