[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Don't pre-create read-only files with --extract --xattrs
From: |
Pavel Raiskup |
Subject: |
[PATCH] Don't pre-create read-only files with --extract --xattrs |
Date: |
Fri, 9 Oct 2020 12:14:08 +0200 |
We used to respect the target file mode when pre-creating files in
set_xattr, so we also pre-created read-only files that we were not able
to open later for writing. This is now fixed, and we always create the
file with S_IWUSR.
Fixes the original bug report https://bugzilla.redhat.com/1886540
* src/extract.c (set_xattr): Blindly add S_IWUSR flag to pre-created
files, to avoid openat failures later.
---
src/extract.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/extract.c b/src/extract.c
index b73a591..2e650ad 100644
--- a/src/extract.c
+++ b/src/extract.c
@@ -865,7 +865,13 @@ set_xattr (char const *file_name, struct tar_stat_info
const *st,
for (;;)
{
- if (!mknodat (chdir_fd, file_name, mode ^ invert_permissions, 0))
+ /* We'll open the file with O_WRONLY later by open_output_file,
+ therefore we need to give us the S_IWUSR bit. If the file was
+ meant to be user-read-only, the permissions will be corrected by
+ the set_stat call. */
+ mode_t initial_mode = mode ^ invert_permissions | S_IWUSR;
+
+ if (!mknodat (chdir_fd, file_name, initial_mode, 0))
{
/* Successfully created file */
xattrs_xattrs_set (st, file_name, typeflag, 0);
--
2.28.0
- [PATCH] Don't pre-create read-only files with --extract --xattrs,
Pavel Raiskup <=