Skip to content

Commit 57f45e7

Browse files
committed
Merge pull request libgit2#2901 from ethomson/win32_mode_bits
win32: limit the mode to `_wopen`/`_waccess`
2 parents 0b2ee7c + 527ed59 commit 57f45e7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/win32/posix_w32.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
* inheritable on Windows, so specify the flag to get default behavior back. */
3434
#define STANDARD_OPEN_FLAGS (_O_BINARY | _O_NOINHERIT)
3535

36+
/* Allowable mode bits on Win32. Using mode bits that are not supported on
37+
* Win32 (eg S_IRWXU) is generally ignored, but Wine warns loudly about it
38+
* so we simply remove them.
39+
*/
40+
#define WIN32_MODE_MASK (_S_IREAD | _S_IWRITE)
41+
3642
/* GetFinalPathNameByHandleW signature */
3743
typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
3844

@@ -343,7 +349,7 @@ int p_open(const char *path, int flags, ...)
343349
va_end(arg_list);
344350
}
345351

346-
return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode);
352+
return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK);
347353
}
348354

349355
int p_creat(const char *path, mode_t mode)
@@ -353,7 +359,9 @@ int p_creat(const char *path, mode_t mode)
353359
if (git_win32_path_from_utf8(buf, path) < 0)
354360
return -1;
355361

356-
return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS, mode);
362+
return _wopen(buf,
363+
_O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS,
364+
mode & WIN32_MODE_MASK);
357365
}
358366

359367
int p_getcwd(char *buffer_out, size_t size)
@@ -607,7 +615,7 @@ int p_access(const char* path, mode_t mode)
607615
if (git_win32_path_from_utf8(buf, path) < 0)
608616
return -1;
609617

610-
return _waccess(buf, mode);
618+
return _waccess(buf, mode & WIN32_MODE_MASK);
611619
}
612620

613621
static int ensure_writable(wchar_t *fpath)

0 commit comments

Comments
 (0)