Author: tfaber
Date: Wed Aug 24 09:45:50 2011
New Revision: 53410
URL:
http://svn.reactos.org/svn/reactos?rev=53410&view=rev
Log:
[EVENTLOG]
- Don't use sizeof for a variable-length structure
- Fix string buffer building
Modified:
trunk/reactos/base/services/eventlog/file.c
trunk/reactos/base/services/eventlog/rpc.c
Modified: trunk/reactos/base/services/eventlog/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/fil…
==============================================================================
--- trunk/reactos/base/services/eventlog/file.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/file.c [iso-8859-1] Wed Aug 24 09:45:50 2011
@@ -959,7 +959,7 @@
PEVENTLOGRECORD pRec;
SYSTEMTIME SysTime;
WCHAR *str;
- UINT i, pos, nStrings;
+ UINT i, pos;
PBYTE Buffer;
dwRecSize =
@@ -983,7 +983,7 @@
dwRecSize += 4;
- Buffer = (BYTE *) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize);
+ Buffer = HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize);
if (!Buffer)
{
@@ -1002,7 +1002,6 @@
pRec->EventID = dwEventId;
pRec->EventType = wType;
- pRec->NumStrings = wNumStrings;
pRec->EventCategory = wCategory;
pos = sizeof(EVENTLOGRECORD);
@@ -1024,14 +1023,13 @@
}
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);
pos += (lstrlenW(str) + 1) * sizeof(WCHAR);
str += lstrlenW(str) + 1;
- nStrings++;
- }
- pRec->NumStrings = nStrings;
+ }
+ pRec->NumStrings = wNumStrings;
pRec->DataOffset = pos;
if (dwDataSize)
Modified: trunk/reactos/base/services/eventlog/rpc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/rpc…
==============================================================================
--- trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] Wed Aug 24 09:45:50 2011
@@ -397,6 +397,7 @@
DWORD lastRec;
DWORD recSize;
DWORD dwStringsSize = 0;
+ DWORD dwUserSidLength = 0;
DWORD dwError = ERROR_SUCCESS;
WCHAR *lpStrings;
int pos = 0;
@@ -439,10 +440,10 @@
DPRINT1("Type %hu: %wZ\n", EventType, Strings[i]);
break;
}
- dwStringsSize += (wcslen(Strings[i]->Buffer) + 1) * sizeof(WCHAR);
- }
-
- lpStrings = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, dwStringsSize * 2);
+ dwStringsSize += Strings[i]->Length + sizeof UNICODE_NULL;
+ }
+
+ lpStrings = HeapAlloc(GetProcessHeap(), 0, dwStringsSize);
if (!lpStrings)
{
DPRINT1("Failed to allocate heap\n");
@@ -451,10 +452,14 @@
for (i = 0; i < NumStrings; i++)
{
- wcscpy((WCHAR*)(lpStrings + pos), Strings[i]->Buffer);
- pos += (wcslen(Strings[i]->Buffer) + 1) * sizeof(WCHAR);
- }
-
+ CopyMemory(lpStrings + pos, Strings[i]->Buffer, Strings[i]->Length);
+ 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,
lastRec,
EventType,
@@ -462,10 +467,10 @@
EventID,
lpLogHandle->szName,
ComputerName->Buffer,
- sizeof(RPC_SID),
- &UserSID,
+ dwUserSidLength,
+ UserSID,
NumStrings,
- (WCHAR*)lpStrings,
+ lpStrings,
DataSize,
Data);