summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>2024-03-18 12:14:21 +0100
committerAlejandro Colomar <alx@kernel.org>2024-03-21 02:44:12 +0100
commit000619344ddb01aa2e9aa746583f7c5a52ce56fe (patch)
tree2b776188790d669e53452f4dff6c242a337fc798
parent51a0d94a08920a2d3edc52919692cdbd25f07d6d (diff)
lib/copydir: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. Issue #973 Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
-rw-r--r--lib/copydir.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/copydir.c b/lib/copydir.c
index 3a22738f..926033af 100644
--- a/lib/copydir.c
+++ b/lib/copydir.c
@@ -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;
}