Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Bail out in SystemNative_CopyFile if access fails. We don't want to p…
Browse files Browse the repository at this point in the history
…roceed if the destination file is read-only.
  • Loading branch information
filipnavara committed May 13, 2019
1 parent 4636a2d commit 780171d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Native/Unix/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,13 +1219,16 @@ int32_t SystemNative_CopyFile(intptr_t sourceFd, const char* srcPath, const char
#if HAVE_CLONEFILE
// For clonefile we need to unlink the destination file first but we need to
// check permission first to ensure we don't try to unlink read-only file
if (access(destPath, W_OK) == 0)
if (access(destPath, W_OK) != 0)
{
ret = unlink(destPath);
if (ret != 0)
{
return ret;
}
errno = EACCES;
return -1;
}

ret = unlink(destPath);
if (ret != 0)
{
return ret;
}
#endif
}
Expand Down

0 comments on commit 780171d

Please sign in to comment.