]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
test if TMPDIR is accessible before using
[apt.git] / apt-pkg / contrib / fileutl.cc
index c51eee737ca660116f750aa3d2b808c2281fb361..47033eadff01d0f6edac3a912122aa496badb3f1 100644 (file)
@@ -2066,9 +2066,11 @@ std::string GetTempDir()                                         /*{{{*/
       tmpdir = P_tmpdir;
 #endif
 
-   // check that tmpdir is set and exists
    struct stat st;
-   if (!tmpdir || strlen(tmpdir) == 0 || stat(tmpdir, &st) != 0)
+   if (!tmpdir || strlen(tmpdir) == 0 || // tmpdir is set
+        stat(tmpdir, &st) != 0 || (st.st_mode & S_IFDIR) == 0 || // exists and is directory
+        access(tmpdir, R_OK | W_OK | X_OK) != 0 // current user has rwx access to directory
+      )
       tmpdir = "/tmp";
 
    return string(tmpdir);