Fix EnumServiceGroupW and EnumServiceStatus[A/W]:
- If lpServices is NULL or cbBufSize is less than sizeof(ENUM_SERVICE_STATUS/W) pass a pointer to an internal status buffer to REnumServiceGrouW or REnumServiceStatusA/W.
svn path=/trunk/; revision=53210
LPDWORD lpResumeHandle,
LPCWSTR lpGroup)
{
LPDWORD lpResumeHandle,
LPCWSTR lpGroup)
{
+ ENUM_SERVICE_STATUSW ServiceStatus;
LPENUM_SERVICE_STATUSW lpStatusPtr;
LPENUM_SERVICE_STATUSW lpStatusPtr;
DWORD dwError;
DWORD dwCount;
DWORD dwError;
DWORD dwCount;
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
+ }
+
RpcTryExcept
{
if (lpGroup == NULL)
RpcTryExcept
{
if (lpGroup == NULL)
dwError = REnumServicesStatusW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
dwError = REnumServicesStatusW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
dwError = REnumServiceGroupW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
dwError = REnumServiceGroupW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle,
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices;
- for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
+ if (*lpServicesReturned > 0)
- if (lpStatusPtr->lpServiceName)
- lpStatusPtr->lpServiceName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
+ for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
+ {
+ if (lpStatusPtr->lpServiceName)
+ lpStatusPtr->lpServiceName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
+ if (lpStatusPtr->lpDisplayName)
+ lpStatusPtr->lpDisplayName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle)
{
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle)
{
+ ENUM_SERVICE_STATUSA ServiceStatus;
LPENUM_SERVICE_STATUSA lpStatusPtr;
LPENUM_SERVICE_STATUSA lpStatusPtr;
DWORD dwError;
DWORD dwCount;
DWORD dwError;
DWORD dwCount;
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
+ }
+
RpcTryExcept
{
dwError = REnumServicesStatusA((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
RpcTryExcept
{
dwError = REnumServicesStatusA((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices;
- for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
+ if (*lpServicesReturned > 0)
- if (lpStatusPtr->lpServiceName)
- lpStatusPtr->lpServiceName =
- (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
+ for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
+ {
+ if (lpStatusPtr->lpServiceName)
+ lpStatusPtr->lpServiceName =
+ (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
+ if (lpStatusPtr->lpDisplayName)
+ lpStatusPtr->lpDisplayName =
+ (LPSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle)
{
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle)
{
+ ENUM_SERVICE_STATUSW ServiceStatus;
LPENUM_SERVICE_STATUSW lpStatusPtr;
LPENUM_SERVICE_STATUSW lpStatusPtr;
DWORD dwError;
DWORD dwCount;
DWORD dwError;
DWORD dwCount;
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
+ }
+
RpcTryExcept
{
dwError = REnumServicesStatusW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
RpcTryExcept
{
dwError = REnumServicesStatusW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA)
{
- lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices;
- for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
+ if (*lpServicesReturned > 0)
- if (lpStatusPtr->lpServiceName)
- lpStatusPtr->lpServiceName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
+ for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
+ {
+ if (lpStatusPtr->lpServiceName)
+ lpStatusPtr->lpServiceName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpServiceName);
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);
+ if (lpStatusPtr->lpDisplayName)
+ lpStatusPtr->lpDisplayName =
+ (LPWSTR)((ULONG_PTR)lpServices + (ULONG_PTR)lpStatusPtr->lpDisplayName);