Skip to content

Commit bb03da9

Browse files
committed
[EVENTVWR] Additions to the Event Viewer.
- Don't hardcode a buffer length in ExpandEnvironmentStringsW() call. - If no file name is associated to a log (ErrorLog->FileName == NULL), don't try to attempt looking at its file properties. This also allows avoiding a crash in the FindFirstFileW() call under certain conditions on Windows.
1 parent ab240d1 commit bb03da9

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

base/applications/mscutils/eventvwr/eventvwr.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,30 +3459,40 @@ InitPropertiesDlg(HWND hDlg, PEVENTLOG EventLog)
34593459
FileName = EventLog->FileName;
34603460
if (FileName && *FileName)
34613461
{
3462-
ExpandEnvironmentStringsW(FileName, wszBuf, MAX_PATH);
3462+
ExpandEnvironmentStringsW(FileName, wszBuf, ARRAYSIZE(wszBuf));
34633463
FileName = wszBuf;
34643464
}
3465+
else
3466+
{
3467+
FileName = L"";
3468+
}
34653469
SetDlgItemTextW(hDlg, IDC_LOGFILE, FileName);
34663470

3467-
/*
3468-
* The general problem here (and in the shell as well) is that
3469-
* GetFileAttributesEx fails for files that are opened without
3470-
* shared access. To retrieve file information for those we need
3471-
* to use something else: FindFirstFile, on the full file name.
3472-
*/
3473-
3474-
Success = GetFileAttributesExW(FileName,
3475-
GetFileExInfoStandard,
3476-
(LPWIN32_FILE_ATTRIBUTE_DATA)&FileInfo);
3477-
if (!Success)
3471+
if (FileName && *FileName)
3472+
{
3473+
/*
3474+
* The general problem here (and in the shell as well) is that
3475+
* GetFileAttributesEx fails for files that are opened without
3476+
* shared access. To retrieve file information for those we need
3477+
* to use something else: FindFirstFile, on the full file name.
3478+
*/
3479+
Success = GetFileAttributesExW(FileName,
3480+
GetFileExInfoStandard,
3481+
(LPWIN32_FILE_ATTRIBUTE_DATA)&FileInfo);
3482+
if (!Success)
3483+
{
3484+
HANDLE hFind = FindFirstFileW(FileName, &FileInfo);
3485+
Success = (hFind != INVALID_HANDLE_VALUE);
3486+
if (Success)
3487+
FindClose(hFind);
3488+
}
3489+
}
3490+
else
34783491
{
3479-
HANDLE hFind = FindFirstFileW(FileName, &FileInfo);
3480-
Success = (hFind != INVALID_HANDLE_VALUE);
3481-
if (Success)
3482-
FindClose(hFind);
3492+
Success = FALSE;
34833493
}
34843494

3485-
// Starting there, FileName is invalid (because it uses wszBuf)
3495+
/* Starting there, FileName becomes invalid because we are reusing wszBuf */
34863496

34873497
if (Success)
34883498
{

0 commit comments

Comments
 (0)