[SERVICES]

Code cleaning and removing bugs.
Patch by Hermès Bélusca.

I did not include the changes to EnumServicesStatusW because it does not improve the code but introduces an unnecessary exception.

See issue #7127 for more details.

svn path=/trunk/; revision=56763
This commit is contained in:
Eric Kohl 2012-06-20 21:38:46 +00:00
parent aa5e222460
commit 490c8a5648

View file

@ -777,20 +777,17 @@ EnumDependentServicesA(SC_HANDLE hService,
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{ {
if (*lpServicesReturned > 0) for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{ {
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) if (lpStatusPtr->lpServiceName)
{ lpStatusPtr->lpServiceName =
if (lpStatusPtr->lpServiceName) (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
lpStatusPtr->lpServiceName =
(LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
if (lpStatusPtr->lpDisplayName) if (lpStatusPtr->lpDisplayName)
lpStatusPtr->lpDisplayName = lpStatusPtr->lpDisplayName =
(LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
lpStatusPtr++; lpStatusPtr++;
}
} }
} }
@ -856,20 +853,17 @@ EnumDependentServicesW(SC_HANDLE hService,
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{ {
if (*lpServicesReturned > 0) for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{ {
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) if (lpStatusPtr->lpServiceName)
{ lpStatusPtr->lpServiceName =
if (lpStatusPtr->lpServiceName) (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
lpStatusPtr->lpServiceName =
(LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
if (lpStatusPtr->lpDisplayName) if (lpStatusPtr->lpDisplayName)
lpStatusPtr->lpDisplayName = lpStatusPtr->lpDisplayName =
(LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
lpStatusPtr++; lpStatusPtr++;
}
} }
} }
@ -961,20 +955,17 @@ EnumServiceGroupW(SC_HANDLE hSCManager,
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{ {
if (*lpServicesReturned > 0) for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{ {
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) if (lpStatusPtr->lpServiceName)
{ lpStatusPtr->lpServiceName =
if (lpStatusPtr->lpServiceName) (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
lpStatusPtr->lpServiceName =
(LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
if (lpStatusPtr->lpDisplayName) if (lpStatusPtr->lpDisplayName)
lpStatusPtr->lpDisplayName = lpStatusPtr->lpDisplayName =
(LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
lpStatusPtr++; lpStatusPtr++;
}
} }
} }
@ -1020,46 +1011,10 @@ EnumServicesStatusA(SC_HANDLE hSCManager,
return FALSE; return FALSE;
} }
if (dwServiceType != SERVICE_DRIVER && dwServiceType != SERVICE_WIN32) if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSA))
{
if (pcbBytesNeeded && lpServicesReturned)
{
*pcbBytesNeeded = 0;
*lpServicesReturned = 0;
}
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (dwServiceState != SERVICE_ACTIVE && dwServiceState != SERVICE_INACTIVE && dwServiceState != SERVICE_STATE_ALL)
{
if (pcbBytesNeeded)
*pcbBytesNeeded = 0;
if (lpServicesReturned)
*lpServicesReturned = 0;
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (!pcbBytesNeeded || !lpServicesReturned)
{
SetLastError(ERROR_INVALID_ADDRESS);
return FALSE;
}
if (!lpServices && cbBufSize != 0)
{
SetLastError(ERROR_INVALID_ADDRESS);
return FALSE;
}
if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
{ {
lpStatusPtr = &ServiceStatus; lpStatusPtr = &ServiceStatus;
dwBufferSize = sizeof(ENUM_SERVICE_STATUSW); dwBufferSize = sizeof(ENUM_SERVICE_STATUSA);
} }
else else
{ {
@ -1086,20 +1041,17 @@ EnumServicesStatusA(SC_HANDLE hSCManager,
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{ {
if (*lpServicesReturned > 0) for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{ {
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) if (lpStatusPtr->lpServiceName)
{ lpStatusPtr->lpServiceName =
if (lpStatusPtr->lpServiceName) (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
lpStatusPtr->lpServiceName =
(LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
if (lpStatusPtr->lpDisplayName) if (lpStatusPtr->lpDisplayName)
lpStatusPtr->lpDisplayName = lpStatusPtr->lpDisplayName =
(LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
lpStatusPtr++; lpStatusPtr++;
}
} }
} }
@ -1175,20 +1127,17 @@ EnumServicesStatusW(SC_HANDLE hSCManager,
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{ {
if (*lpServicesReturned > 0) for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
{ {
for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) if (lpStatusPtr->lpServiceName)
{ lpStatusPtr->lpServiceName =
if (lpStatusPtr->lpServiceName) (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
lpStatusPtr->lpServiceName =
(LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
if (lpStatusPtr->lpDisplayName) if (lpStatusPtr->lpDisplayName)
lpStatusPtr->lpDisplayName = lpStatusPtr->lpDisplayName =
(LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName); (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
lpStatusPtr++; lpStatusPtr++;
}
} }
} }
@ -1336,6 +1285,12 @@ EnumServicesStatusExW(SC_HANDLE hSCManager,
return FALSE; return FALSE;
} }
if (!hSCManager)
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (lpServices == NULL || if (lpServices == NULL ||
cbBufSize < sizeof(ENUM_SERVICE_STATUS_PROCESSW)) cbBufSize < sizeof(ENUM_SERVICE_STATUS_PROCESSW))
{ {