summaryrefslogtreecommitdiff
path: root/libarchive/archive_util.c
diff options
context:
space:
mode:
authorCristian Rodríguez <crrodriguez@opensuse.org>2020-07-27 10:11:33 -0400
committerCristian Rodríguez <crodriguez@owncloud.com>2020-07-27 10:24:27 -0400
commitb6bb4e0e62facb1f787e2e269182a5ce5b5cfdf9 (patch)
treef01fd90bec076edd4b2d641ee5d5d1fa74863401 /libarchive/archive_util.c
parent4f8359552b3b4291d5dac7efc657bbe696a3b2f5 (diff)
downloadlibarchive-b6bb4e0e62facb1f787e2e269182a5ce5b5cfdf9.tar.gz
use O_TMPFILE if it works/is supported in __archive_mktemp
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.
Diffstat (limited to 'libarchive/archive_util.c')
-rw-r--r--libarchive/archive_util.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c
index c76ecc5b..b1582edb 100644
--- a/libarchive/archive_util.c
+++ b/libarchive/archive_util.c
@@ -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)