]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
use O_TMPFILE if it works/is supported in __archive_mktemp 1422/head
authorCristian Rodríguez <crrodriguez@opensuse.org>
Mon, 27 Jul 2020 14:11:33 +0000 (10:11 -0400)
committerCristian Rodríguez <crodriguez@owncloud.com>
Mon, 27 Jul 2020 14:24:27 +0000 (10:24 -0400)
This makes the function safer on linux since the file is warrantied to never
be visible on the filesystem, cannot be linked anywhere unless O_EXCL is
not specified and it is lost forever on any kind of program termination.

libarchive/archive_util.c

index c76ecc5b05b1fca53402b3e22ee2d0e2c6830409..b1582edbe308ccc3a00d5af393583c505e8c2c14 100644 (file)
@@ -433,6 +433,11 @@ __archive_mktemp(const char *tmpdir)
                if (temp_name.s[temp_name.length-1] != '/')
                        archive_strappend_char(&temp_name, '/');
        }
+#ifdef O_TMPFILE
+       fd = open(temp_name.s, O_RDWR|O_CLOEXEC|O_TMPFILE|O_EXCL, 0600); 
+       if(fd >= 0)
+               goto exit_tmpfile;
+#endif
        archive_strcat(&temp_name, "libarchive_XXXXXX");
        fd = mkstemp(temp_name.s);
        if (fd < 0)