[EVENTVWR] Add missing output buffer size parameters to some routines.

Fix also some bugs encountered while testing.
This commit is contained in:
Hermès Bélusca-Maïto 2025-05-03 23:37:49 +02:00
parent 39ce22150a
commit fad52db479
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 169 additions and 104 deletions

View file

@ -4,7 +4,7 @@
* PURPOSE: Event Log Viewer main file. * PURPOSE: Event Log Viewer main file.
* COPYRIGHT: Copyright 2007 Marc Piulachs <marc.piulachs@codexchange.net> * COPYRIGHT: Copyright 2007 Marc Piulachs <marc.piulachs@codexchange.net>
* Copyright 2008-2016 Eric Kohl <eric.kohl@reactos.org> * Copyright 2008-2016 Eric Kohl <eric.kohl@reactos.org>
* Copyright 2016-2022 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org> * Copyright 2016-2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
*/ */
#include "eventvwr.h" #include "eventvwr.h"
@ -1440,7 +1440,7 @@ LONG EventLogFilter_Release(IN PEVENTLOGFILTER EventLogFilter)
void void
TrimNulls(LPWSTR s) TrimNulls(LPWSTR s)
{ {
WCHAR *c; PWCHAR c;
if (s != NULL) if (s != NULL)
{ {
@ -1451,17 +1451,20 @@ TrimNulls(LPWSTR s)
} }
} }
DWORD SIZE_T
GetExpandedFilePathName( GetExpandedFilePathName(
IN LPCWSTR ComputerName OPTIONAL, _In_opt_ PCWSTR ComputerName,
IN LPCWSTR lpFileName, _In_ PCWSTR FileName,
OUT LPWSTR lpFullFileName OPTIONAL, _Out_writes_z_(nSize) PWSTR pFullFileName,
IN DWORD nSize) _In_ SIZE_T nSize)
{ {
SIZE_T dwLength; SIZE_T dwLength;
if (nSize == 0)
return 0;
/* Determine the needed size after expansion of any environment strings */ /* Determine the needed size after expansion of any environment strings */
dwLength = ExpandEnvironmentStringsW(lpFileName, NULL, 0); dwLength = ExpandEnvironmentStringsW(FileName, NULL, 0);
if (dwLength == 0) if (dwLength == 0)
{ {
/* We failed, bail out */ /* We failed, bail out */
@ -1487,15 +1490,14 @@ GetExpandedFilePathName(
if (dwLength > nSize) if (dwLength > nSize)
{ {
/* No, return the needed size in characters (includes NULL-terminator) */ /* No, return the needed size in characters (includes NULL-terminator) */
*pFullFileName = UNICODE_NULL;
return dwLength; return dwLength;
} }
/* Now expand the file path */ /* Now expand the file path */
ASSERT(dwLength <= nSize);
/* Expand any existing environment strings */ /* Expand any existing environment strings */
if (ExpandEnvironmentStringsW(lpFileName, lpFullFileName, dwLength) == 0) if (ExpandEnvironmentStringsW(FileName, pFullFileName, dwLength) == 0)
{ {
/* We failed, bail out */ /* We failed, bail out */
return 0; return 0;
@ -1508,16 +1510,16 @@ GetExpandedFilePathName(
/* Note that we previously skipped any potential leading backslashes */ /* Note that we previously skipped any potential leading backslashes */
/* Replace ':' by '$' in the drive letter */ /* Replace ':' by '$' in the drive letter */
if (*lpFullFileName && lpFullFileName[1] == L':') if (*pFullFileName && pFullFileName[1] == L':')
lpFullFileName[1] = L'$'; pFullFileName[1] = L'$';
/* Prepend the computer name */ /* Prepend the computer name */
MoveMemory(lpFullFileName + 2 + wcslen(ComputerName) + 1, MoveMemory(pFullFileName + 2 + wcslen(ComputerName) + 1,
lpFullFileName, dwLength * sizeof(WCHAR) - (2 + wcslen(ComputerName) + 1) * sizeof(WCHAR)); pFullFileName, dwLength * sizeof(WCHAR) - (2 + wcslen(ComputerName) + 1) * sizeof(WCHAR));
lpFullFileName[0] = L'\\'; pFullFileName[0] = L'\\';
lpFullFileName[1] = L'\\'; pFullFileName[1] = L'\\';
wcsncpy(lpFullFileName + 2, ComputerName, wcslen(ComputerName)); wcsncpy(pFullFileName + 2, ComputerName, wcslen(ComputerName));
lpFullFileName[2 + wcslen(ComputerName)] = L'\\'; pFullFileName[2 + wcslen(ComputerName)] = L'\\';
} }
/* Return the number of stored characters (includes NULL-terminator) */ /* Return the number of stored characters (includes NULL-terminator) */
@ -1525,27 +1527,38 @@ GetExpandedFilePathName(
} }
BOOL BOOL
GetEventMessageFileDLL(IN LPCWSTR lpLogName, GetEventMessageFileDLL(
IN LPCWSTR SourceName, _In_ PCWSTR LogName,
IN LPCWSTR EntryName, _In_ PCWSTR SourceName,
OUT PWCHAR lpModuleName) // TODO: Add IN DWORD BufLen _In_ PCWSTR EntryName,
_Out_writes_z_(cchName) PWSTR pModuleName,
_In_ SIZE_T cchName)
{ {
BOOL Success = FALSE; BOOL Success = FALSE;
LONG Result; LONG Result;
DWORD dwType, dwSize; DWORD dwType, dwSize;
WCHAR szModuleName[MAX_PATH]; WCHAR szModuleName[MAX_PATH];
WCHAR szKeyName[MAX_PATH]; PWSTR KeyPath;
SIZE_T cbKeyPath;
HKEY hLogKey = NULL; HKEY hLogKey = NULL;
HKEY hSourceKey = NULL; HKEY hSourceKey = NULL;
StringCbCopyW(szKeyName, sizeof(szKeyName), EVENTLOG_BASE_KEY); if (cchName == 0)
StringCbCatW(szKeyName, sizeof(szKeyName), lpLogName); return FALSE;
Result = RegOpenKeyExW(hkMachine, cbKeyPath = (wcslen(EVENTLOG_BASE_KEY) + wcslen(LogName) + 1) * sizeof(WCHAR);
szKeyName, KeyPath = HeapAlloc(GetProcessHeap(), 0, cbKeyPath);
0, if (!KeyPath)
KEY_READ, {
&hLogKey); ShowWin32Error(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
StringCbCopyW(KeyPath, cbKeyPath, EVENTLOG_BASE_KEY);
StringCbCatW(KeyPath, cbKeyPath, LogName);
Result = RegOpenKeyExW(hkMachine, KeyPath, 0, KEY_READ, &hLogKey);
HeapFree(GetProcessHeap(), 0, KeyPath);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
return FALSE; return FALSE;
@ -1554,11 +1567,9 @@ GetEventMessageFileDLL(IN LPCWSTR lpLogName,
0, 0,
KEY_QUERY_VALUE, KEY_QUERY_VALUE,
&hSourceKey); &hSourceKey);
RegCloseKey(hLogKey);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{
RegCloseKey(hLogKey);
return FALSE; return FALSE;
}
dwSize = sizeof(szModuleName); dwSize = sizeof(szModuleName);
Result = RegQueryValueExW(hSourceKey, Result = RegQueryValueExW(hSourceKey,
@ -1569,34 +1580,42 @@ GetEventMessageFileDLL(IN LPCWSTR lpLogName,
&dwSize); &dwSize);
if ((Result != ERROR_SUCCESS) || (dwType != REG_EXPAND_SZ && dwType != REG_SZ)) if ((Result != ERROR_SUCCESS) || (dwType != REG_EXPAND_SZ && dwType != REG_SZ))
{ {
szModuleName[0] = UNICODE_NULL; *szModuleName = UNICODE_NULL;
} }
else else
{ {
/* NULL-terminate the string and expand it */ /* NULL-terminate the string and expand it */
szModuleName[dwSize / sizeof(WCHAR) - 1] = UNICODE_NULL; szModuleName[dwSize / sizeof(WCHAR) - 1] = UNICODE_NULL;
GetExpandedFilePathName(lpComputerName, szModuleName, lpModuleName, ARRAYSIZE(szModuleName)); Success =
Success = TRUE; (GetExpandedFilePathName(lpComputerName, szModuleName,
pModuleName, cchName) != 0 && *pModuleName);
} }
RegCloseKey(hSourceKey); RegCloseKey(hSourceKey);
RegCloseKey(hLogKey);
return Success; return Success;
} }
BOOL BOOL
GetEventCategory(IN LPCWSTR KeyName, GetEventCategory(
IN LPCWSTR SourceName, _In_ PCWSTR KeyName,
IN PEVENTLOGRECORD pevlr, _In_ PCWSTR SourceName,
OUT PWCHAR CategoryName) // TODO: Add IN DWORD BufLen _In_ PEVENTLOGRECORD pevlr,
_Out_writes_z_(cchName) PWSTR CategoryName,
_In_ SIZE_T cchName)
{ {
BOOL Success = FALSE; BOOL Success = FALSE;
WCHAR szMessageDLL[MAX_PATH]; WCHAR szMessageDLL[MAX_PATH];
LPWSTR lpMsgBuf = NULL; LPWSTR lpMsgBuf;
if (!GetEventMessageFileDLL(KeyName, SourceName, EVENT_CATEGORY_MESSAGE_FILE, szMessageDLL)) if (cchName == 0)
return FALSE;
if (!GetEventMessageFileDLL(KeyName, SourceName, EVENT_CATEGORY_MESSAGE_FILE,
szMessageDLL, _countof(szMessageDLL)))
{
goto Quit; goto Quit;
}
/* Retrieve the message string without appending extra newlines */ /* Retrieve the message string without appending extra newlines */
lpMsgBuf = lpMsgBuf =
@ -1612,7 +1631,7 @@ GetEventCategory(IN LPCWSTR KeyName,
TrimNulls(lpMsgBuf); TrimNulls(lpMsgBuf);
/* Copy the category name */ /* Copy the category name */
StringCchCopyW(CategoryName, MAX_PATH, lpMsgBuf); StringCchCopyW(CategoryName, cchName, lpMsgBuf);
/* Free the buffer allocated by FormatMessage */ /* Free the buffer allocated by FormatMessage */
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
@ -1626,7 +1645,7 @@ Quit:
{ {
if (pevlr->EventCategory != 0) if (pevlr->EventCategory != 0)
{ {
StringCchPrintfW(CategoryName, MAX_PATH, L"(%lu)", pevlr->EventCategory); StringCchPrintfW(CategoryName, cchName, L"(%lu)", pevlr->EventCategory);
Success = TRUE; Success = TRUE;
} }
} }
@ -1634,12 +1653,14 @@ Quit:
return Success; return Success;
} }
// NOTE: Used by evtdetctl.c
BOOL // NOTE: Used by evtdetctl.c BOOL
GetEventMessage(IN LPCWSTR KeyName, GetEventMessage(
IN LPCWSTR SourceName, _In_ PCWSTR KeyName,
IN PEVENTLOGRECORD pevlr, _In_ PCWSTR SourceName,
OUT PWCHAR EventText) // TODO: Add IN DWORD BufLen _In_ PEVENTLOGRECORD pevlr,
_Out_writes_z_(cchText) PWSTR EventText,
_In_ SIZE_T cchText)
{ {
BOOL Success = FALSE; BOOL Success = FALSE;
DWORD i; DWORD i;
@ -1647,26 +1668,36 @@ GetEventMessage(IN LPCWSTR KeyName,
WCHAR SourceModuleName[1024]; WCHAR SourceModuleName[1024];
WCHAR ParameterModuleName[1024]; WCHAR ParameterModuleName[1024];
BOOL IsParamModNameCached = FALSE; BOOL IsParamModNameCached = FALSE;
LPWSTR lpMsgBuf = NULL; LPWSTR lpMsgBuf;
LPWSTR szStringArray, szMessage; LPWSTR szStringArray, szMessage;
LPWSTR *szArguments; LPWSTR *szArguments;
if (cchText == 0)
return FALSE;
/* Get the event string array */ /* Get the event string array */
szStringArray = (LPWSTR)((LPBYTE)pevlr + pevlr->StringOffset); szStringArray = (LPWSTR)((LPBYTE)pevlr + pevlr->StringOffset);
/* NOTE: GetEventMessageFileDLL can return a comma-separated list of DLLs */ /* NOTE: GetEventMessageFileDLL can return a comma-separated list of DLLs */
if (!GetEventMessageFileDLL(KeyName, SourceName, EVENT_MESSAGE_FILE, SourceModuleName)) if (!GetEventMessageFileDLL(KeyName, SourceName, EVENT_MESSAGE_FILE,
SourceModuleName, _countof(SourceModuleName)))
{
goto Quit; goto Quit;
}
/* Allocate space for insertion strings */ /* Allocate space for insertion strings */
szArguments = HeapAlloc(GetProcessHeap(), 0, pevlr->NumStrings * sizeof(LPVOID)); szArguments = HeapAlloc(GetProcessHeap(), 0, pevlr->NumStrings * sizeof(LPVOID));
if (!szArguments) if (!szArguments)
goto Quit; goto Quit;
// TODO: Revisit this whole IsParamModNameCached later,
// see commits c1ecc98f60 (r71368) and d5ba2a3784 (r71958).
*ParameterModuleName = UNICODE_NULL; // TEMP fix in case GetEventMessageFileDLL fails.
if (!IsParamModNameCached) if (!IsParamModNameCached)
{ {
/* Now that the parameter file list is loaded, no need to reload it at the next run! */ /* Now that the parameter file list is loaded, no need to reload it at the next run! */
IsParamModNameCached = GetEventMessageFileDLL(KeyName, SourceName, EVENT_PARAMETER_MESSAGE_FILE, ParameterModuleName); IsParamModNameCached = GetEventMessageFileDLL(KeyName, SourceName, EVENT_PARAMETER_MESSAGE_FILE,
ParameterModuleName, _countof(ParameterModuleName));
// FIXME: If the string loading failed the first time, no need to retry it just after??? // FIXME: If the string loading failed the first time, no need to retry it just after???
} }
@ -1679,7 +1710,7 @@ GetEventMessage(IN LPCWSTR KeyName,
/* /*
* HACK: * HACK:
* We do some hackish preformatting of the cached event strings... * We do some hackish preformatting of the cached event strings...
* That's because after we pass the string to FormatMessage * That's because below, we pass the string to FormatMessage
* (via GetMessageStringFromDllList) with the FORMAT_MESSAGE_ARGUMENT_ARRAY * (via GetMessageStringFromDllList) with the FORMAT_MESSAGE_ARGUMENT_ARRAY
* flag, instead of ignoring the insertion parameters and do the formatting * flag, instead of ignoring the insertion parameters and do the formatting
* by ourselves. Therefore, the resulting string should have the parameter * by ourselves. Therefore, the resulting string should have the parameter
@ -1737,7 +1768,7 @@ GetEventMessage(IN LPCWSTR KeyName,
} }
/* Copy the event text */ /* Copy the event text */
StringCchCopyW(EventText, EVENT_MESSAGE_EVENTTEXT_BUFFER, lpMsgBuf); StringCchCopyW(EventText, cchText, lpMsgBuf);
/* Free the buffer allocated by FormatMessage */ /* Free the buffer allocated by FormatMessage */
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
@ -1748,17 +1779,31 @@ GetEventMessage(IN LPCWSTR KeyName,
Quit: Quit:
if (!Success) if (!Success)
{ {
/* Get a read-only pointer to the "event-not-found" string */ /* Get a read-only pointer to the "Event-Not-Found" string */
lpMsgBuf = HeapAlloc(GetProcessHeap(), 0, EVENT_MESSAGE_EVENTTEXT_BUFFER * sizeof(WCHAR)); SIZE_T cchResLen =
LoadStringW(hInst, IDS_EVENTSTRINGIDNOTFOUND, lpMsgBuf, EVENT_MESSAGE_EVENTTEXT_BUFFER); LoadStringW(hInst, IDS_EVENTSTRINGIDNOTFOUND, (PWSTR)&szMessage, 0);
StringCchPrintfW(EventText, EVENT_MESSAGE_EVENTTEXT_BUFFER, lpMsgBuf, (pevlr->EventID & 0xFFFF), SourceName);
lpMsgBuf = HeapAlloc(GetProcessHeap(), 0, (cchResLen + 1) * sizeof(WCHAR));
if (lpMsgBuf)
{
StringCchCopyNW(lpMsgBuf, cchResLen + 1, szMessage, cchResLen);
szMessage = lpMsgBuf;
}
else
{
/* Use a hardcoded format string */
szMessage = L"Event ID ( %lu ), Source ( %s )\n\n";
}
StringCchPrintfW(EventText, cchText, szMessage, (pevlr->EventID & 0xFFFF), SourceName);
if (lpMsgBuf)
HeapFree(GetProcessHeap(), 0, lpMsgBuf);
/* Append the strings */ /* Append the strings */
szMessage = szStringArray; szMessage = szStringArray;
for (i = 0; i < pevlr->NumStrings; i++) for (i = 0; i < pevlr->NumStrings; i++)
{ {
StringCchCatW(EventText, EVENT_MESSAGE_EVENTTEXT_BUFFER, szMessage); StringCchCatW(EventText, cchText, szMessage);
StringCchCatW(EventText, EVENT_MESSAGE_EVENTTEXT_BUFFER, L"\n"); StringCchCatW(EventText, cchText, L"\n");
szMessage += wcslen(szMessage) + 1; szMessage += wcslen(szMessage) + 1;
} }
} }
@ -1767,49 +1812,56 @@ Quit:
} }
VOID VOID
GetEventType(IN WORD dwEventType, GetEventType(
OUT PWCHAR eventTypeText) // TODO: Add IN DWORD BufLen _In_ WORD dwEventType,
_Out_writes_z_(cchText) PWSTR pszEventType,
_In_ SIZE_T cchText)
{ {
switch (dwEventType) switch (dwEventType)
{ {
case EVENTLOG_ERROR_TYPE: case EVENTLOG_ERROR_TYPE:
LoadStringW(hInst, IDS_EVENTLOG_ERROR_TYPE, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_ERROR_TYPE, pszEventType, cchText);
break; break;
case EVENTLOG_WARNING_TYPE: case EVENTLOG_WARNING_TYPE:
LoadStringW(hInst, IDS_EVENTLOG_WARNING_TYPE, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_WARNING_TYPE, pszEventType, cchText);
break; break;
case EVENTLOG_INFORMATION_TYPE: case EVENTLOG_INFORMATION_TYPE:
LoadStringW(hInst, IDS_EVENTLOG_INFORMATION_TYPE, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_INFORMATION_TYPE, pszEventType, cchText);
break; break;
case EVENTLOG_SUCCESS: case EVENTLOG_SUCCESS:
LoadStringW(hInst, IDS_EVENTLOG_SUCCESS, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_SUCCESS, pszEventType, cchText);
break; break;
case EVENTLOG_AUDIT_SUCCESS: case EVENTLOG_AUDIT_SUCCESS:
LoadStringW(hInst, IDS_EVENTLOG_AUDIT_SUCCESS, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_AUDIT_SUCCESS, pszEventType, cchText);
break; break;
case EVENTLOG_AUDIT_FAILURE: case EVENTLOG_AUDIT_FAILURE:
LoadStringW(hInst, IDS_EVENTLOG_AUDIT_FAILURE, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_AUDIT_FAILURE, pszEventType, cchText);
break; break;
default: default:
LoadStringW(hInst, IDS_EVENTLOG_UNKNOWN_TYPE, eventTypeText, MAX_LOADSTRING); LoadStringW(hInst, IDS_EVENTLOG_UNKNOWN_TYPE, pszEventType, cchText);
break; break;
} }
} }
BOOL BOOL
GetEventUserName(IN PEVENTLOGRECORD pelr, GetEventUserName(
IN OUT PSID *pLastSid, _In_ PEVENTLOGRECORD pelr,
OUT PWCHAR pszUser) // TODO: Add IN DWORD BufLen _Inout_ PSID *pLastSid,
_Out_writes_z_(cchUser) PWSTR pszUser,
_In_ SIZE_T cchUser)
{ {
PSID pCurrentSid; PSID pCurrentSid;
PWSTR StringSid; PWSTR StringSid;
WCHAR szName[1024]; WCHAR szName[1024];
WCHAR szDomain[1024]; WCHAR szDomain[1024];
SID_NAME_USE peUse; SID_NAME_USE peUse;
DWORD cchName = ARRAYSIZE(szName); DWORD cchName = _countof(szName);
DWORD cchDomain = ARRAYSIZE(szDomain); DWORD cchDomain = _countof(szDomain);
BOOL Success = FALSE; BOOL Success = FALSE;
if (cchUser == 0)
return FALSE;
/* Point to the SID */ /* Point to the SID */
pCurrentSid = (PSID)((LPBYTE)pelr + pelr->UserSidOffset); pCurrentSid = (PSID)((LPBYTE)pelr + pelr->UserSidOffset);
@ -1840,15 +1892,15 @@ GetEventUserName(IN PEVENTLOGRECORD pelr,
&cchDomain, &cchDomain,
&peUse)) &peUse))
{ {
StringCchCopyW(pszUser, MAX_PATH, szName); StringCchCopyW(pszUser, cchUser, szName);
Success = TRUE; Success = TRUE;
} }
else if (ConvertSidToStringSidW(pCurrentSid, &StringSid)) else if (ConvertSidToStringSidW(pCurrentSid, &StringSid))
{ {
/* Copy the string only if the user-provided buffer is big enough */ /* Copy the string only if the user-provided buffer is big enough */
if (wcslen(StringSid) + 1 <= MAX_PATH) // + 1 for NULL-terminator if (wcslen(StringSid) + 1 <= cchUser) // + 1 for NULL-terminator
{ {
StringCchCopyW(pszUser, MAX_PATH, StringSid); StringCchCopyW(pszUser, cchUser, StringSid);
Success = TRUE; Success = TRUE;
} }
else else
@ -2190,15 +2242,19 @@ EnumEventsThread(IN LPVOID lpParameter)
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &time, NULL, szLocalTime, ARRAYSIZE(szLocalTime)); GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &time, NULL, szLocalTime, ARRAYSIZE(szLocalTime));
/* Get the username that generated the event, and filter it */ /* Get the username that generated the event, and filter it */
lpszUsername = GetEventUserName(pEvlrTmp, &pLastSid, szUsername) ? szUsername : szNoUsername; lpszUsername = GetEventUserName(pEvlrTmp, &pLastSid,
szUsername, _countof(szUsername))
? szUsername : szNoUsername;
if (!FilterByString(EventLogFilter->Users, lpszUsername)) if (!FilterByString(EventLogFilter->Users, lpszUsername))
goto SkipEvent; goto SkipEvent;
// TODO: Filter by event ID and category // TODO: Filter by event ID and category
GetEventType(pEvlrTmp->EventType, szEventTypeText); GetEventType(pEvlrTmp->EventType, szEventTypeText, _countof(szEventTypeText));
lpszCategoryName = GetEventCategory(EventLog->LogName, lpszSourceName, pEvlrTmp, szCategory) ? szCategory : szNoCategory; lpszCategoryName = GetEventCategory(EventLog->LogName, lpszSourceName, pEvlrTmp,
szCategory, _countof(szCategory))
? szCategory : szNoCategory;
StringCbPrintfW(szEventID, sizeof(szEventID), L"%u", (pEvlrTmp->EventID & 0xFFFF)); StringCbPrintfW(szEventID, sizeof(szEventID), L"%u", (pEvlrTmp->EventID & 0xFFFF));
StringCbPrintfW(szCategoryID, sizeof(szCategoryID), L"%u", pEvlrTmp->EventCategory); StringCbPrintfW(szCategoryID, sizeof(szCategoryID), L"%u", pEvlrTmp->EventCategory);
@ -2712,14 +2768,16 @@ MyRegisterClass(HINSTANCE hInstance)
BOOL BOOL
GetDisplayNameFileAndID(IN LPCWSTR lpLogName, GetDisplayNameFileAndID(
OUT PWCHAR lpModuleName, // TODO: Add IN DWORD BufLen _In_ PCWSTR LogName,
OUT PDWORD pdwMessageID) _Out_writes_z_(cchName) PWSTR pModuleName,
_In_ SIZE_T cchName,
_Out_ PDWORD pdwMessageID)
{ {
BOOL Success = FALSE; BOOL Success = FALSE;
LONG Result; LONG Result;
HKEY hLogKey; HKEY hLogKey;
WCHAR *KeyPath; PWSTR KeyPath;
SIZE_T cbKeyPath; SIZE_T cbKeyPath;
DWORD dwType, cbData; DWORD dwType, cbData;
DWORD dwMessageID = 0; DWORD dwMessageID = 0;
@ -2728,7 +2786,10 @@ GetDisplayNameFileAndID(IN LPCWSTR lpLogName,
/* Use a default value for the message ID */ /* Use a default value for the message ID */
*pdwMessageID = 0; *pdwMessageID = 0;
cbKeyPath = (wcslen(EVENTLOG_BASE_KEY) + wcslen(lpLogName) + 1) * sizeof(WCHAR); if (cchName == 0)
return FALSE;
cbKeyPath = (wcslen(EVENTLOG_BASE_KEY) + wcslen(LogName) + 1) * sizeof(WCHAR);
KeyPath = HeapAlloc(GetProcessHeap(), 0, cbKeyPath); KeyPath = HeapAlloc(GetProcessHeap(), 0, cbKeyPath);
if (!KeyPath) if (!KeyPath)
{ {
@ -2737,7 +2798,7 @@ GetDisplayNameFileAndID(IN LPCWSTR lpLogName,
} }
StringCbCopyW(KeyPath, cbKeyPath, EVENTLOG_BASE_KEY); StringCbCopyW(KeyPath, cbKeyPath, EVENTLOG_BASE_KEY);
StringCbCatW(KeyPath, cbKeyPath, lpLogName); StringCbCatW(KeyPath, cbKeyPath, LogName);
Result = RegOpenKeyExW(hkMachine, KeyPath, 0, KEY_QUERY_VALUE, &hLogKey); Result = RegOpenKeyExW(hkMachine, KeyPath, 0, KEY_QUERY_VALUE, &hLogKey);
HeapFree(GetProcessHeap(), 0, KeyPath); HeapFree(GetProcessHeap(), 0, KeyPath);
@ -2756,14 +2817,15 @@ GetDisplayNameFileAndID(IN LPCWSTR lpLogName,
&cbData); &cbData);
if ((Result != ERROR_SUCCESS) || (dwType != REG_EXPAND_SZ && dwType != REG_SZ)) if ((Result != ERROR_SUCCESS) || (dwType != REG_EXPAND_SZ && dwType != REG_SZ))
{ {
szModuleName[0] = UNICODE_NULL; *szModuleName = UNICODE_NULL;
} }
else else
{ {
/* NULL-terminate the string and expand it */ /* NULL-terminate the string and expand it */
szModuleName[cbData / sizeof(WCHAR) - 1] = UNICODE_NULL; szModuleName[cbData / sizeof(WCHAR) - 1] = UNICODE_NULL;
GetExpandedFilePathName(lpComputerName, szModuleName, lpModuleName, ARRAYSIZE(szModuleName)); Success =
Success = TRUE; (GetExpandedFilePathName(lpComputerName, szModuleName,
pModuleName, cchName) != 0 && *pModuleName);
} }
/* /*
@ -2940,8 +3002,8 @@ BuildLogListAndFilterList(IN LPCWSTR lpComputerName)
/* Get the display name for the event log */ /* Get the display name for the event log */
lpDisplayName = NULL; lpDisplayName = NULL;
ZeroMemory(szModuleName, sizeof(szModuleName)); *szModuleName = UNICODE_NULL;
if (GetDisplayNameFileAndID(LogName, szModuleName, &dwMessageID)) if (GetDisplayNameFileAndID(LogName, szModuleName, _countof(szModuleName), &dwMessageID))
{ {
/* Retrieve the message string without appending extra newlines */ /* Retrieve the message string without appending extra newlines */
lpDisplayName = lpDisplayName =
@ -3857,9 +3919,9 @@ InitPropertiesDlg(HWND hDlg, PEVENTLOG EventLog)
LPWSTR FileName; LPWSTR FileName;
HKEY hLogKey; HKEY hLogKey;
WCHAR *KeyPath; PWSTR KeyPath;
DWORD cbData;
SIZE_T cbKeyPath; SIZE_T cbKeyPath;
DWORD cbData;
if (EventLog->Permanent) if (EventLog->Permanent)
{ {
@ -3929,7 +3991,7 @@ Quit:
if (FileName && *FileName) if (FileName && *FileName)
{ {
/* Expand the file name. If the log file is on a remote computer, retrieve the network share form of the file name. */ /* Expand the file name. If the log file is on a remote computer, retrieve the network share form of the file name. */
GetExpandedFilePathName(EventLog->ComputerName, FileName, wszBuf, ARRAYSIZE(wszBuf)); GetExpandedFilePathName(EventLog->ComputerName, FileName, wszBuf, _countof(wszBuf));
FileName = wszBuf; FileName = wszBuf;
} }
else else
@ -4040,7 +4102,7 @@ SavePropertiesDlg(HWND hDlg, PEVENTLOG EventLog)
LONG Result; LONG Result;
DWORD dwMaxSize = 0, dwRetention = 0; DWORD dwMaxSize = 0, dwRetention = 0;
HKEY hLogKey; HKEY hLogKey;
WCHAR *KeyPath; PWSTR KeyPath;
SIZE_T cbKeyPath; SIZE_T cbKeyPath;
if (!EventLog->Permanent) if (!EventLog->Permanent)

View file

@ -4,7 +4,7 @@
* PURPOSE: Event Log Viewer header. * PURPOSE: Event Log Viewer header.
* COPYRIGHT: Copyright 2007 Marc Piulachs <marc.piulachs@codexchange.net> * COPYRIGHT: Copyright 2007 Marc Piulachs <marc.piulachs@codexchange.net>
* Copyright 2008-2016 Eric Kohl <eric.kohl@reactos.org> * Copyright 2008-2016 Eric Kohl <eric.kohl@reactos.org>
* Copyright 2016-2022 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org> * Copyright 2016-2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
*/ */
#ifndef _EVENTVWR_PCH_ #ifndef _EVENTVWR_PCH_

View file

@ -29,10 +29,12 @@ extern WCHAR szTitle[];
extern HWND hwndListView; extern HWND hwndListView;
extern BOOL extern BOOL
GetEventMessage(IN LPCWSTR KeyName, GetEventMessage(
IN LPCWSTR SourceName, _In_ PCWSTR KeyName,
IN PEVENTLOGRECORD pevlr, _In_ PCWSTR SourceName,
OUT PWCHAR EventText); _In_ PEVENTLOGRECORD pevlr,
_Out_writes_z_(cchText) PWSTR EventText,
_In_ SIZE_T cchText);
typedef struct _DETAILDATA typedef struct _DETAILDATA
@ -113,7 +115,8 @@ DisplayEvent(
EnableDlgItem(hDlg, IDC_WORDSRADIO, bEventData); EnableDlgItem(hDlg, IDC_WORDSRADIO, bEventData);
// FIXME: At the moment we support only one event log in the filter // FIXME: At the moment we support only one event log in the filter
GetEventMessage(EventLogFilter->EventLogs[0]->LogName, szSource, pevlr, szEventText); GetEventMessage(EventLogFilter->EventLogs[0]->LogName, szSource, pevlr,
szEventText, _countof(szEventText));
SetDlgItemTextW(hDlg, IDC_EVENTTEXTEDIT, szEventText); SetDlgItemTextW(hDlg, IDC_EVENTTEXTEDIT, szEventText);
DisplayEventData(hDlg, pDetailData); DisplayEventData(hDlg, pDetailData);