[NOTEPAD] Use FILE_SHARE_READ and OPEN_ALWAYS for writing (#6880)

Fix access denial on writing file "C:\freeldr.ini".
JIRA issue: CORE-19575
- Add FILE_SHARE_READ flag and delete
  FILE_SHARE_WRITE 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:22:17 +09:00 committed by GitHub
parent 3e97f76a33
commit a64cccd711
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -249,8 +249,10 @@ static BOOL DoSaveFile(VOID)
WaitCursor(TRUE);
hFile = CreateFileW(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
/* Use OPEN_ALWAYS instead of CREATE_ALWAYS in order to succeed
* even if the file has HIDDEN or SYSTEM attributes */
hFile = CreateFileW(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_READ,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
ShowLastError();
@ -281,6 +283,8 @@ static BOOL DoSaveFile(VOID)
}
}
/* Truncate the file and close it */
SetEndOfFile(hFile);
CloseHandle(hFile);
if (bRet)