From d7888265761bc3b7fc6fc385e62687754c8195c3 Mon Sep 17 00:00:00 2001 From: Sylvain Petreolle Date: Mon, 9 Jan 2012 22:47:16 +0000 Subject: [PATCH] [SVCHOST] Convert to Unicode. Fix buffer overruns and bad maths when UNICODE is defined. Patch by Samuel Serapion. svn path=/trunk/; revision=54893 --- reactos/base/services/svchost/CMakeLists.txt | 2 +- reactos/base/services/svchost/svchost.c | 12 ++++++------ reactos/base/services/svchost/svchost.rbuild | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/reactos/base/services/svchost/CMakeLists.txt b/reactos/base/services/svchost/CMakeLists.txt index 637b6931edd..b5593117322 100644 --- a/reactos/base/services/svchost/CMakeLists.txt +++ b/reactos/base/services/svchost/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(svchost svchost.c svchost.rc) -set_module_type(svchost win32cui) +set_module_type(svchost win32cui UNICODE) add_importlibs(svchost advapi32 msvcrt kernel32 ntdll) add_cd_file(TARGET svchost DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/services/svchost/svchost.c b/reactos/base/services/svchost/svchost.c index c79ffae2009..ede1971605a 100644 --- a/reactos/base/services/svchost/svchost.c +++ b/reactos/base/services/svchost/svchost.c @@ -93,7 +93,7 @@ BOOL PrepareService(LPCTSTR ServiceName) } /* Convert possible %SystemRoot% to a real path */ - BufferSize = ExpandEnvironmentStrings(Buffer, DllPath, sizeof(DllPath)); + BufferSize = ExpandEnvironmentStrings(Buffer, DllPath, _countof(DllPath)); if (0 == BufferSize) { DPRINT1("Invalid ServiceDll path: %s\n", Buffer); @@ -124,7 +124,7 @@ BOOL PrepareService(LPCTSTR ServiceName) } memset(Service, 0, sizeof(SERVICE)); - Service->Name = HeapAlloc(GetProcessHeap(), 0, _tcslen(ServiceName) + sizeof(TCHAR)); + Service->Name = HeapAlloc(GetProcessHeap(), 0, (_tcslen(ServiceName)+1) * sizeof(TCHAR)); if (NULL == Service->Name) { DPRINT1("Not enough memory for service: %s\n", ServiceName); @@ -199,7 +199,7 @@ DWORD LoadServiceCategory(LPCTSTR ServiceCategory) if (TRUE == PrepareService(ServiceName)) ++NrOfServices; - BufferIndex += (Length + 1) * sizeof(TCHAR); + BufferIndex += Length + 1; ServiceName = &Buffer[BufferIndex]; } @@ -238,7 +238,7 @@ int _tmain (int argc, LPTSTR argv []) PSERVICE Service = FirstService; /* Fill the service table */ - for (i = 0; i < NrOfServices; ++i) + for (i = 0; i < NrOfServices; i++) { DPRINT("Loading service: %s\n", Service->Name); ServiceTable[i].lpServiceName = Service->Name; @@ -251,7 +251,7 @@ int _tmain (int argc, LPTSTR argv []) ServiceTable[i].lpServiceProc = NULL; if (FALSE == StartServiceCtrlDispatcher(ServiceTable)) - printf("Failed to start service control dispatcher, ErrorCode: %lu\n", GetLastError()); + DPRINT1("Failed to start service control dispatcher, ErrorCode: %lu\n", GetLastError()); HeapFree(GetProcessHeap(), 0, ServiceTable); } @@ -260,7 +260,7 @@ int _tmain (int argc, LPTSTR argv []) DPRINT1("Not enough memory for the service table, trying to allocate %u bytes\n", sizeof(SERVICE_TABLE_ENTRY) * (NrOfServices + 1)); } - DPRINT1("Freeing services...\n"); + DPRINT("Freeing services...\n"); FreeServices(); return 0; diff --git a/reactos/base/services/svchost/svchost.rbuild b/reactos/base/services/svchost/svchost.rbuild index 3831d516fe1..831bb274155 100644 --- a/reactos/base/services/svchost/svchost.rbuild +++ b/reactos/base/services/svchost/svchost.rbuild @@ -1,6 +1,6 @@ - + . advapi32 svchost.c