]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Prefer issymlinkat
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Nov 2025 16:08:58 +0000 (08:08 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Nov 2025 23:10:48 +0000 (15:10 -0800)
* gnulib.modules: Add issymlinkat, already an indirect dependency.
* src/extract.c: Include issymlink.h.
(is_directory_link, open_output_file):
Prefer issymlinkat to doing it by hand.

gnulib.modules
src/extract.c

index 4044ce9760b27d69045b79feeaa891862e1366bd..dd643272f980af21d5a0f3807483167c5af0d1e3 100644 (file)
@@ -69,6 +69,7 @@ idx
 intprops
 inttostr
 inttypes-h
+issymlinkat
 largefile
 lchown
 limits-h
index 54386629f60b98efab268bde23760085542558bb..179a2d7b63856b71fddd10a112a22a16e2853d01 100644 (file)
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <flexmember.h>
 #include <hash.h>
+#include <issymlink.h>
 #include <priv-set.h>
 #include <root-uid.h>
 #include <same-inode.h>
@@ -1065,8 +1066,7 @@ apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links)
 static bool
 is_directory_link (char const *file_name, struct stat *st)
 {
-  char buf[1];
-  return (0 <= readlinkat (chdir_fd, file_name, buf, sizeof buf)
+  return (issymlinkat (chdir_fd, file_name)
          && fstatat (chdir_fd, file_name, st, 0) == 0
          && S_ISDIR (st->st_mode));
 }
@@ -1239,14 +1239,11 @@ open_output_file (char const *file_name, char typeflag, mode_t mode,
      separately.  There's a race condition, but that cannot be avoided
      on hosts lacking O_NOFOLLOW.  */
   if (! HAVE_WORKING_O_NOFOLLOW
-      && overwriting_old_files && ! dereference_option)
+      && overwriting_old_files && ! dereference_option
+      && issymlinkat (chdir_fd, file_name))
     {
-      char buf[1];
-      if (0 <= readlinkat (chdir_fd, file_name, buf, sizeof buf))
-       {
-         errno = ELOOP;
-         return -1;
-       }
+      errno = ELOOP;
+      return -1;
     }
 
   fd = openat (chdir_fd, file_name, openflag, mode);