]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/copydir:copy_entry(): use temporary stat buffer
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>
Mon, 18 Mar 2024 11:14:21 +0000 (12:14 +0100)
committerAlejandro Colomar <alx@kernel.org>
Thu, 21 Mar 2024 01:44:12 +0000 (02:44 +0100)
There are no guarantees that fstatat() does not clobber the stat
buffer on errors.

Use a temporary buffer so that the following code sees correct
attributes of the source entry.

Issue #973

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
lib/copydir.c

index 3a22738fc414c8b04cb8295043b02e9c0ad3caa9..926033afc02681d1dae481dff6b8832f3381d786 100644 (file)
@@ -400,6 +400,7 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst,
 {
        int err = 0;
        struct stat sb;
+       struct stat tmp_sb;
        struct link_name *lp;
        struct timespec mt[2];
 
@@ -423,7 +424,7 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst,
        * If the destination already exists do nothing.
        * This is after the copy_dir above to still iterate into subdirectories.
        */
-       if (fstatat(dst->dirfd, dst->name, &sb, AT_SYMLINK_NOFOLLOW) != -1) {
+       if (fstatat(dst->dirfd, dst->name, &tmp_sb, AT_SYMLINK_NOFOLLOW) != -1) {
                return err;
        }