Skip to content

Commit

Permalink
lib/copydir.c: copy_entry(): Use temporary stat buffer
Browse files Browse the repository at this point in the history
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: <#973>
Signed-off-by: Enrico Scholz <[email protected]>
Reviewed-by: Alejandro Colomar <[email protected]>
Cherry-picked-from: 0006193 ("lib/copydir:copy_entry(): use temporary stat buffer")
Link: <#974>
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
ensc authored and alejandro-colomar committed Mar 21, 2024
1 parent 89d26e0 commit aed99b1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/copydir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
}

Expand Down

0 comments on commit aed99b1

Please sign in to comment.