patch 9.2.0661: unintended wipe of Vim's temp dir, causes errors

Commit: 
https://github.com/vim/vim/commit/4a792c9cc5654d0b134c56b4b8acd61b081c83b9
Author: Christian Brabandt <[email protected]>
Date:   Tue Jun 16 20:11:03 2026 +0000

    patch 9.2.0661: unintended wipe of Vim's temp dir, causes errors
    
    Problem:  Unintended wipe of Vim's temp dir, causes errors and may also
              leak temporary data (David Leadbeater)
    Solution: In vim_tempname() verify the temp directory still exists (via
              its open file descriptor) and re-create it if it was removed.
    
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/fileio.c b/src/fileio.c
index af0360dc8..255e1b33d 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5370,6 +5370,19 @@ vim_closetempdir(void)
     closedir(vim_tempdir_dp);
     vim_tempdir_dp = NULL;
 }
+
+/*
+ * Return true if the temp directory we created is gone.
+ */
+    static bool
+vim_tempdir_gone(void)
+{
+    stat_T     st;
+
+    if (vim_tempdir_dp == NULL)
+       return false;
+    return fstat(dirfd(vim_tempdir_dp), &st) < 0 || st.st_nlink == 0;
+}
 # endif
 
 /*
@@ -5450,6 +5463,15 @@ vim_tempname(
     stat_T     st;
 # endif
 
+# if defined(UNIX) && defined(HAVE_FLOCK) && defined(HAVE_DIRFD)
+    // if the temp directory is gone, force re-creation of it
+    if (vim_tempdir != NULL && vim_tempdir_gone())
+    {
+       vim_closetempdir();
+       VIM_CLEAR(vim_tempdir);
+    }
+# endif
+
     /*
      * This will create a directory for private use by this instance of Vim.
      * This is done once, and the same directory is used for all temp files.
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index a07ed6ead..3797fb73a 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -7729,6 +7729,23 @@ func Test_builtin_fullcommand()
 
 endfunc
 
+" Test that temporary directory is re-created after wipeout {{{1
+func Test_delete_temp_dir()
+  " assumes Unix has always flock/dirfd support
+  CheckUnix
+  let a = tempname()
+  let dir = fnamemodify(a, ':h')
+  call delete(dir, 'rf')
+
+  let newdir = fnamemodify(tempname(), ':h')
+  call assert_notequal(dir, newdir)
+  " if the test fails (e.g. because vim has no support for flock/dirfd,
+  " recreate the directory, to prevent followup test failures
+  if dir == newdir
+    call mkdir(dir, '', 0o700)
+  endif
+endfunc
+
 
"-------------------------------------------------------------------------------
 " Modelines                                                                {{{1
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
diff --git a/src/version.c b/src/version.c
index b548ef9c9..9824f5891 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    661,
 /**/
     660,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1wZaQ7-0013Uh-CI%40256bit.org.

Raspunde prin e-mail lui