From b5f68e498196a5c11e5ffdac2af3b19ff288579e Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 6 Feb 2010 14:10:18 +0000 Subject: [PATCH] Convert offset to pointers when enumeration functions return ERROR_SUCCESS or ERROR_MORE_DATA because there is something to convert in both cases. svn path=/trunk/; revision=45459 --- reactos/dll/win32/advapi32/service/scm.c | 147 ++++++++++++----------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/reactos/dll/win32/advapi32/service/scm.c b/reactos/dll/win32/advapi32/service/scm.c index 2e3c79f7e8c..64f0b81f6c2 100644 --- a/reactos/dll/win32/advapi32/service/scm.c +++ b/reactos/dll/win32/advapi32/service/scm.c @@ -820,6 +820,23 @@ EnumDependentServicesA(SC_HANDLE hService, } RpcEndExcept; + if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) + { + lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices; + 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++; + } + } + if (dwError != ERROR_SUCCESS) { ERR("REnumDependentServicesA() failed (Error %lu)\n", dwError); @@ -827,20 +844,6 @@ EnumDependentServicesA(SC_HANDLE hService, return FALSE; } - lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices; - 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++; - } - TRACE("EnumDependentServicesA() done\n"); return TRUE; @@ -881,6 +884,23 @@ EnumDependentServicesW(SC_HANDLE hService, } RpcEndExcept; + if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) + { + lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices; + 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++; + } + } + if (dwError != ERROR_SUCCESS) { ERR("REnumDependentServicesW() failed (Error %lu)\n", dwError); @@ -888,20 +908,6 @@ EnumDependentServicesW(SC_HANDLE hService, return FALSE; } - lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices; - 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++; - } - TRACE("EnumDependentServicesW() done\n"); return TRUE; @@ -1012,6 +1018,23 @@ EnumServicesStatusA(SC_HANDLE hSCManager, } RpcEndExcept; + if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) + { + lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices; + 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++; + } + } + if (dwError != ERROR_SUCCESS) { ERR("REnumServicesStatusA() failed (Error %lu)\n", dwError); @@ -1019,20 +1042,6 @@ EnumServicesStatusA(SC_HANDLE hSCManager, return FALSE; } - lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices; - 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++; - } - TRACE("EnumServicesStatusA() done\n"); return TRUE; @@ -1083,6 +1092,23 @@ EnumServicesStatusW(SC_HANDLE hSCManager, } RpcEndExcept; + if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) + { + lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices; + 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++; + } + } + if (dwError != ERROR_SUCCESS) { ERR("REnumServicesStatusW() failed (Error %lu)\n", dwError); @@ -1090,20 +1116,6 @@ EnumServicesStatusW(SC_HANDLE hSCManager, return FALSE; } - lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices; - 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++; - } - TRACE("EnumServicesStatusW() done\n"); return TRUE; @@ -1145,7 +1157,6 @@ EnumServicesStatusExA(SC_HANDLE hSCManager, return FALSE; } - RpcTryExcept { dwError = REnumServicesStatusExA((SC_RPC_HANDLE)hSCManager, @@ -1165,13 +1176,7 @@ EnumServicesStatusExA(SC_HANDLE hSCManager, } RpcEndExcept; - if (dwError == ERROR_MORE_DATA) - { - WARN("Required buffer size %ul\n", *pcbBytesNeeded); - SetLastError(dwError); - return FALSE; - } - else if (dwError == ERROR_SUCCESS) + if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) { lpStatusPtr = (LPENUM_SERVICE_STATUS_PROCESSA)lpServices; for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) @@ -1187,7 +1192,8 @@ EnumServicesStatusExA(SC_HANDLE hSCManager, lpStatusPtr++; } } - else + + if (dwError != ERROR_SUCCESS) { ERR("REnumServicesStatusExA() failed (Error %lu)\n", dwError); SetLastError(dwError); @@ -1242,13 +1248,7 @@ EnumServicesStatusExW(SC_HANDLE hSCManager, } RpcEndExcept; - if (dwError == ERROR_MORE_DATA) - { - WARN("Required buffer size %ul\n", *pcbBytesNeeded); - SetLastError(dwError); - return FALSE; - } - else if (dwError == ERROR_SUCCESS) + if (dwError == ERROR_SUCCESS || dwError == ERROR_MORE_DATA) { lpStatusPtr = (LPENUM_SERVICE_STATUS_PROCESSW)lpServices; for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++) @@ -1264,7 +1264,8 @@ EnumServicesStatusExW(SC_HANDLE hSCManager, lpStatusPtr++; } } - else + + if (dwError != ERROR_SUCCESS) { ERR("REnumServicesStatusExW() failed (Error %lu)\n", dwError); SetLastError(dwError);