[WORDPAD] Use FILE_SHARE_READ and OPEN_ALWAYS for writing (#6883)

Follow-up to #6880. Fix access denial on
writing file "C:\freeldr.ini".
JIRA issue: CORE-19575
- Add FILE_SHARE_READ flag in CreateFileW
  call.
- Use OPEN_ALWAYS instead of
  CREATE_ALWAYS, and then explicitly use
  SetEndOfFile function.
This commit is contained in:
Katayama Hirofumi MZ 2024-05-15 01:23:30 +09:00 committed by GitHub
parent a64cccd711
commit 2b0d1faaa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -843,8 +843,15 @@ static BOOL DoSaveFile(LPCWSTR wszSaveFileName, WPARAM format)
EDITSTREAM stream;
LRESULT ret;
#ifdef __REACTOS__
/* Use OPEN_ALWAYS instead of CREATE_ALWAYS in order to succeed
* even if the file has HIDDEN or SYSTEM attributes */
hFile = CreateFileW(wszSaveFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
#else
hFile = CreateFileW(wszSaveFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
#endif
if(hFile == INVALID_HANDLE_VALUE)
{
@ -870,6 +877,10 @@ static BOOL DoSaveFile(LPCWSTR wszSaveFileName, WPARAM format)
ret = SendMessageW(hEditorWnd, EM_STREAMOUT, format, (LPARAM)&stream);
#ifdef __REACTOS__
/* Truncate the file and close it */
SetEndOfFile(hFile);
#endif
CloseHandle(hFile);
SetFocus(hEditorWnd);