[SERVICES]

Removing some code defects discovered by Coverity.
Patch by Hermès Bélusca.
See issue #7105 for more details.

svn path=/trunk/; revision=56702
This commit is contained in:
Eric Kohl 2012-06-06 23:01:53 +00:00
parent e39b696116
commit 0d6a879b5a
2 changed files with 36 additions and 17 deletions

View file

@ -19,19 +19,26 @@
DWORD DWORD
ScmLoadDriver(PSERVICE lpService) ScmLoadDriver(PSERVICE lpService)
{ {
WCHAR szDriverPath[MAX_PATH]; PWSTR pszDriverPath;
UNICODE_STRING DriverPath; UNICODE_STRING DriverPath;
NTSTATUS Status; NTSTATUS Status;
DWORD dwError = ERROR_SUCCESS; DWORD dwError = ERROR_SUCCESS;
/* Build the driver path */ /* Build the driver path */
wcscpy(szDriverPath, /* 52 = wcslen(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\") */
pszDriverPath = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
(52 + wcslen(lpService->lpServiceName) + 1) * sizeof(WCHAR));
if (pszDriverPath == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
wcscpy(pszDriverPath,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"); L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
wcscat(szDriverPath, wcscat(pszDriverPath,
lpService->lpServiceName); lpService->lpServiceName);
RtlInitUnicodeString(&DriverPath, RtlInitUnicodeString(&DriverPath,
szDriverPath); pszDriverPath);
/* FIXME: Acquire privilege */ /* FIXME: Acquire privilege */
@ -45,6 +52,8 @@ ScmLoadDriver(PSERVICE lpService)
dwError = RtlNtStatusToDosError(Status); dwError = RtlNtStatusToDosError(Status);
} }
HeapFree(GetProcessHeap(), 0, pszDriverPath);
return dwError; return dwError;
} }
@ -52,19 +61,26 @@ ScmLoadDriver(PSERVICE lpService)
DWORD DWORD
ScmUnloadDriver(PSERVICE lpService) ScmUnloadDriver(PSERVICE lpService)
{ {
WCHAR szDriverPath[MAX_PATH]; PWSTR pszDriverPath;
UNICODE_STRING DriverPath; UNICODE_STRING DriverPath;
NTSTATUS Status; NTSTATUS Status;
DWORD dwError = ERROR_SUCCESS; DWORD dwError = ERROR_SUCCESS;
/* Build the driver path */ /* Build the driver path */
wcscpy(szDriverPath, /* 52 = wcslen(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\") */
pszDriverPath = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
(52 + wcslen(lpService->lpServiceName) + 1) * sizeof(WCHAR));
if (pszDriverPath == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
wcscpy(pszDriverPath,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"); L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
wcscat(szDriverPath, wcscat(pszDriverPath,
lpService->lpServiceName); lpService->lpServiceName);
RtlInitUnicodeString(&DriverPath, RtlInitUnicodeString(&DriverPath,
szDriverPath); pszDriverPath);
/* FIXME: Acquire privilege */ /* FIXME: Acquire privilege */
@ -77,6 +93,8 @@ ScmUnloadDriver(PSERVICE lpService)
dwError = RtlNtStatusToDosError(Status); dwError = RtlNtStatusToDosError(Status);
} }
HeapFree(GetProcessHeap(), 0, pszDriverPath);
return dwError; return dwError;
} }

View file

@ -405,6 +405,11 @@ ScmConvertToBootPathName(wchar_t *CanonName, wchar_t **RelativeName)
DPRINT("ScmConvertToBootPathName %S\n", CanonName); DPRINT("ScmConvertToBootPathName %S\n", CanonName);
if (!RelativeName)
return ERROR_INVALID_PARAMETER;
*RelativeName = NULL;
ServiceNameLen = wcslen(CanonName); ServiceNameLen = wcslen(CanonName);
/* First check, if it's already good */ /* First check, if it's already good */
@ -550,7 +555,6 @@ ScmConvertToBootPathName(wchar_t *CanonName, wchar_t **RelativeName)
if (BufferSize > 0xFFFD) if (BufferSize > 0xFFFD)
{ {
DPRINT("Too large buffer required\n"); DPRINT("Too large buffer required\n");
*RelativeName = 0;
if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle); if (SymbolicLinkHandle) NtClose(SymbolicLinkHandle);
HeapFree(GetProcessHeap(), 0, Expanded); HeapFree(GetProcessHeap(), 0, Expanded);
@ -635,14 +639,11 @@ ScmConvertToBootPathName(wchar_t *CanonName, wchar_t **RelativeName)
} }
else else
{ {
/* Failure */
DPRINT("Error, Status = %08X\n", Status); DPRINT("Error, Status = %08X\n", Status);
HeapFree(GetProcessHeap(), 0, Expanded); HeapFree(GetProcessHeap(), 0, Expanded);
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
} }
/* Failure */
*RelativeName = NULL;
return ERROR_INVALID_PARAMETER;
} }
@ -1114,7 +1115,7 @@ DWORD RControlService(
DesiredAccess = SERVICE_PAUSE_CONTINUE; DesiredAccess = SERVICE_PAUSE_CONTINUE;
break; break;
case SERVICE_INTERROGATE: case SERVICE_CONTROL_INTERROGATE:
DesiredAccess = SERVICE_INTERROGATE; DesiredAccess = SERVICE_INTERROGATE;
break; break;
@ -2989,7 +2990,7 @@ DWORD RQueryServiceConfigW(
lpConfig->lpDependencies = (LPWSTR)((ULONG_PTR)lpStr - (ULONG_PTR)lpConfig); lpConfig->lpDependencies = (LPWSTR)((ULONG_PTR)lpStr - (ULONG_PTR)lpConfig);
if (lpDependencies != NULL) if (lpDependencies != NULL)
lpStr += dwDependenciesLength * sizeof(WCHAR); lpStr += dwDependenciesLength;
else else
lpStr += (wcslen(lpStr) + 1); lpStr += (wcslen(lpStr) + 1);
@ -4105,7 +4106,7 @@ DWORD RQueryServiceConfigA(
&lpDependencies, &lpDependencies,
&dwDependenciesLength); &dwDependenciesLength);
dwRequiredSize = sizeof(QUERY_SERVICE_CONFIGW); dwRequiredSize = sizeof(QUERY_SERVICE_CONFIGA);
if (lpImagePath != NULL) if (lpImagePath != NULL)
dwRequiredSize += wcslen(lpImagePath) + 1; dwRequiredSize += wcslen(lpImagePath) + 1;
@ -4148,7 +4149,7 @@ DWORD RQueryServiceConfigA(
lpStr = (LPSTR)(lpServiceConfig + 1); lpStr = (LPSTR)(lpServiceConfig + 1);
/* NOTE: Strings that are NULL for QUERY_SERVICE_CONFIG are pointers to empty strings. /* NOTE: Strings that are NULL for QUERY_SERVICE_CONFIG are pointers to empty strings.
Verified in WINXP*/ Verified in WINXP */
if (lpImagePath) if (lpImagePath)
{ {