Author: ekohl
Date: Sat Aug 13 19:57:32 2011
New Revision: 53210
URL:
http://svn.reactos.org/svn/reactos?rev=53210&view=rev
Log:
[ADVAPI32]
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.
Modified:
trunk/reactos/dll/win32/advapi32/service/scm.c
Modified: trunk/reactos/dll/win32/advapi32/service/scm.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/service…
==============================================================================
--- trunk/reactos/dll/win32/advapi32/service/scm.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/service/scm.c [iso-8859-1] Sat Aug 13 19:57:32 2011
@@ -875,7 +875,9 @@
LPDWORD lpResumeHandle,
LPCWSTR lpGroup)
{
+ ENUM_SERVICE_STATUSW ServiceStatus;
LPENUM_SERVICE_STATUSW lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
DWORD dwCount;
@@ -885,6 +887,17 @@
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
+ }
+
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
}
RpcTryExcept
@@ -894,8 +907,8 @@
dwError = REnumServicesStatusW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
@@ -905,8 +918,8 @@
dwError = REnumServiceGroupW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle,
@@ -921,18 +934,20 @@
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);
-
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPWSTR)((ULONG_PTR)lpServices +
(ULONG_PTR)lpStatusPtr->lpDisplayName);
-
- lpStatusPtr++;
+ 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);
+
+ lpStatusPtr++;
+ }
}
}
@@ -964,7 +979,9 @@
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle)
{
+ ENUM_SERVICE_STATUSA ServiceStatus;
LPENUM_SERVICE_STATUSA lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
DWORD dwCount;
@@ -1012,13 +1029,24 @@
return FALSE;
}
+ 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,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
@@ -1031,18 +1059,20 @@
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);
-
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPSTR)((ULONG_PTR)lpServices +
(ULONG_PTR)lpStatusPtr->lpDisplayName);
-
- lpStatusPtr++;
+ 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);
+
+ lpStatusPtr++;
+ }
}
}
@@ -1074,7 +1104,9 @@
LPDWORD lpServicesReturned,
LPDWORD lpResumeHandle)
{
+ ENUM_SERVICE_STATUSW ServiceStatus;
LPENUM_SERVICE_STATUSW lpStatusPtr;
+ DWORD dwBufferSize;
DWORD dwError;
DWORD dwCount;
@@ -1084,6 +1116,17 @@
{
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
+ }
+
+ if (lpServices == NULL || cbBufSize < sizeof(ENUM_SERVICE_STATUSW))
+ {
+ lpStatusPtr = &ServiceStatus;
+ dwBufferSize = sizeof(ENUM_SERVICE_STATUSW);
+ }
+ else
+ {
+ lpStatusPtr = lpServices;
+ dwBufferSize = cbBufSize;
}
RpcTryExcept
@@ -1091,8 +1134,8 @@
dwError = REnumServicesStatusW((SC_RPC_HANDLE)hSCManager,
dwServiceType,
dwServiceState,
- (LPBYTE)lpServices,
- cbBufSize,
+ (LPBYTE)lpStatusPtr,
+ dwBufferSize,
pcbBytesNeeded,
lpServicesReturned,
lpResumeHandle);
@@ -1105,18 +1148,20 @@
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);
-
- if (lpStatusPtr->lpDisplayName)
- lpStatusPtr->lpDisplayName =
- (LPWSTR)((ULONG_PTR)lpServices +
(ULONG_PTR)lpStatusPtr->lpDisplayName);
-
- lpStatusPtr++;
+ 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);
+
+ lpStatusPtr++;
+ }
}
}