From: Enrico Scholz Date: Mon, 18 Mar 2024 11:14:21 +0000 (+0100) Subject: lib/copydir.c: copy_entry(): Use temporary stat buffer X-Git-Tag: 4.14.7~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aed99b13e0b8bd3141cb98a5fc04eb214eed9b13;p=thirdparty%2Fshadow.git lib/copydir.c: copy_entry(): Use temporary stat buffer 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. Link: Signed-off-by: Enrico Scholz Reviewed-by: Alejandro Colomar Cherry-picked-from: 000619344ddb ("lib/copydir:copy_entry(): use temporary stat buffer") Link: Signed-off-by: Alejandro Colomar --- diff --git a/lib/copydir.c b/lib/copydir.c index cc1a30d29..fb9343742 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -415,6 +415,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]; @@ -436,7 +437,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 0; }