win: add flag to open file with only FILE_SHARE_READ sharing mode

In order to support file integrity verification and mitigate risk of TOC/TOU vulnerabilities, allow callers to open the file with read only sharing mode.
This commit is contained in:
Robert Waite 2025-08-01 10:32:52 -07:00
parent 2e7c07f4d1
commit 313ca49a09
2 changed files with 3 additions and 0 deletions

View File

@ -684,6 +684,7 @@ typedef struct {
#define UV_FS_O_TEMPORARY _O_TEMPORARY
#define UV_FS_O_TRUNC _O_TRUNC
#define UV_FS_O_WRONLY _O_WRONLY
#define UV_FS_O_SHARE_RDONLY 0x40000000 /* READ ONLY SHARING MODE */
/* fs open() flags supported on other platforms (or mapped on this platform): */
#define UV_FS_O_DIRECT 0x02000000 /* FILE_FLAG_NO_BUFFERING */

View File

@ -482,6 +482,8 @@ void fs__open(uv_fs_t* req) {
*/
if (flags & UV_FS_O_EXLOCK) {
share = 0;
} else if (flags & UV_FS_O_SHARE_RDONLY) {
share = FILE_SHARE_READ;
} else {
share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
}