From: Paul Eggert Date: Tue, 11 Nov 2025 16:08:58 +0000 (-0800) Subject: Prefer issymlinkat X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=382a47f2fdc8fb74300ff077ab0b8097ba115a48;p=thirdparty%2Ftar.git Prefer issymlinkat * 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. --- diff --git a/gnulib.modules b/gnulib.modules index 4044ce97..dd643272 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -69,6 +69,7 @@ idx intprops inttostr inttypes-h +issymlinkat largefile lchown limits-h diff --git a/src/extract.c b/src/extract.c index 54386629..179a2d7b 100644 --- a/src/extract.c +++ b/src/extract.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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);