]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Fix missing type in mknodat() mode argument
authorAnssi Hannula <anssi.hannula@bitwise.fi>
Wed, 6 Nov 2024 10:43:32 +0000 (12:43 +0200)
committerSergey Poznyakoff <gray@gnu.org>
Mon, 12 May 2025 10:18:21 +0000 (13:18 +0300)
Per POSIX, the type of the file to be created should be OR'ed to the
`mode` argument of mknodat().

However, set_xattr() creates an empty file using mknodat() and does not
do that.

E.g. Linux kernel considers zero type as S_IFREG, so the code works on
most systems.

However, e.g. fakeroot, at least up to the current v1.36, does not
consider 0 as S_IFREG, instead creating an invalid file, causing tar to
enter an infinite retry loop when trying to create a file with xattrs
under fakeroot.

Since set_xattr is used only when extracting regular files, fix that
by ORing its mode argument with S_IFREG.

Copyright-paperwork-exempt: Yes

src/extract.c

index d810f10af6098ee762cc617598945b1ea8b840df..5d89458aac8567102c69675c394cae792b8bf179 100644 (file)
@@ -969,7 +969,7 @@ set_xattr (char const *file_name, struct tar_stat_info const *st,
 #ifdef HAVE_XATTRS
   if (xattrs_option && st->xattr_map.xm_size)
     {
-      int r = mknodat (chdir_fd, file_name, mode, 0);
+      int r = mknodat (chdir_fd, file_name, mode | S_IFREG, 0);
       if (r < 0)
        return r;
       xattrs_xattrs_set (st, file_name, typeflag, false);