[EVENTLOG]

- Don't use sizeof for a variable-length structure
- Fix string buffer building

svn path=/trunk/; revision=53410
This commit is contained in:
Thomas Faber 2011-08-24 09:45:50 +00:00
parent 5c6935be69
commit a60b8c477c
2 changed files with 16 additions and 13 deletions

View file

@ -959,7 +959,7 @@ PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
PEVENTLOGRECORD pRec; PEVENTLOGRECORD pRec;
SYSTEMTIME SysTime; SYSTEMTIME SysTime;
WCHAR *str; WCHAR *str;
UINT i, pos, nStrings; UINT i, pos;
PBYTE Buffer; PBYTE Buffer;
dwRecSize = dwRecSize =
@ -983,7 +983,7 @@ PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
dwRecSize += 4; dwRecSize += 4;
Buffer = (BYTE *) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize); Buffer = HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize);
if (!Buffer) if (!Buffer)
{ {
@ -1002,7 +1002,6 @@ PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
pRec->EventID = dwEventId; pRec->EventID = dwEventId;
pRec->EventType = wType; pRec->EventType = wType;
pRec->NumStrings = wNumStrings;
pRec->EventCategory = wCategory; pRec->EventCategory = wCategory;
pos = sizeof(EVENTLOGRECORD); pos = sizeof(EVENTLOGRECORD);
@ -1024,14 +1023,13 @@ PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
} }
pRec->StringOffset = pos; pRec->StringOffset = pos;
for (i = 0, str = lpStrings, nStrings = 0; i < wNumStrings; i++) for (i = 0, str = lpStrings; i < wNumStrings; i++)
{ {
lstrcpyW((WCHAR *) (Buffer + pos), str); lstrcpyW((WCHAR *) (Buffer + pos), str);
pos += (lstrlenW(str) + 1) * sizeof(WCHAR); pos += (lstrlenW(str) + 1) * sizeof(WCHAR);
str += lstrlenW(str) + 1; str += lstrlenW(str) + 1;
nStrings++;
} }
pRec->NumStrings = nStrings; pRec->NumStrings = wNumStrings;
pRec->DataOffset = pos; pRec->DataOffset = pos;
if (dwDataSize) if (dwDataSize)

View file

@ -397,6 +397,7 @@ NTSTATUS ElfrReportEventW(
DWORD lastRec; DWORD lastRec;
DWORD recSize; DWORD recSize;
DWORD dwStringsSize = 0; DWORD dwStringsSize = 0;
DWORD dwUserSidLength = 0;
DWORD dwError = ERROR_SUCCESS; DWORD dwError = ERROR_SUCCESS;
WCHAR *lpStrings; WCHAR *lpStrings;
int pos = 0; int pos = 0;
@ -439,10 +440,10 @@ NTSTATUS ElfrReportEventW(
DPRINT1("Type %hu: %wZ\n", EventType, Strings[i]); DPRINT1("Type %hu: %wZ\n", EventType, Strings[i]);
break; break;
} }
dwStringsSize += (wcslen(Strings[i]->Buffer) + 1) * sizeof(WCHAR); dwStringsSize += Strings[i]->Length + sizeof UNICODE_NULL;
} }
lpStrings = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, dwStringsSize * 2); lpStrings = HeapAlloc(GetProcessHeap(), 0, dwStringsSize);
if (!lpStrings) if (!lpStrings)
{ {
DPRINT1("Failed to allocate heap\n"); DPRINT1("Failed to allocate heap\n");
@ -451,10 +452,14 @@ NTSTATUS ElfrReportEventW(
for (i = 0; i < NumStrings; i++) for (i = 0; i < NumStrings; i++)
{ {
wcscpy((WCHAR*)(lpStrings + pos), Strings[i]->Buffer); CopyMemory(lpStrings + pos, Strings[i]->Buffer, Strings[i]->Length);
pos += (wcslen(Strings[i]->Buffer) + 1) * sizeof(WCHAR); pos += Strings[i]->Length / sizeof(WCHAR);
lpStrings[pos] = UNICODE_NULL;
pos += sizeof UNICODE_NULL / sizeof(WCHAR);
} }
if (UserSID)
dwUserSidLength = FIELD_OFFSET(SID, SubAuthority[UserSID->SubAuthorityCount]);
LogBuffer = LogfAllocAndBuildNewRecord(&recSize, LogBuffer = LogfAllocAndBuildNewRecord(&recSize,
lastRec, lastRec,
EventType, EventType,
@ -462,10 +467,10 @@ NTSTATUS ElfrReportEventW(
EventID, EventID,
lpLogHandle->szName, lpLogHandle->szName,
ComputerName->Buffer, ComputerName->Buffer,
sizeof(RPC_SID), dwUserSidLength,
&UserSID, UserSID,
NumStrings, NumStrings,
(WCHAR*)lpStrings, lpStrings,
DataSize, DataSize,
Data); Data);