advapi32: Fix the parameter checks in QueryServiceStatusEx.
This commit is contained in:
parent
a2f987c338
commit
519fbf6202
|
@ -1172,21 +1172,32 @@ BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel,
|
||||||
|
|
||||||
TRACE("%p %d %p %d %p\n", hService, InfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
|
TRACE("%p %d %p %d %p\n", hService, InfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
|
||||||
|
|
||||||
__TRY
|
if (InfoLevel != SC_STATUS_PROCESS_INFO)
|
||||||
{
|
{
|
||||||
err = svcctl_QueryServiceStatusEx(hService, InfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
|
err = ERROR_INVALID_LEVEL;
|
||||||
}
|
}
|
||||||
__EXCEPT(rpc_filter)
|
else if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
|
||||||
{
|
{
|
||||||
err = map_exception_code(GetExceptionCode());
|
*pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
|
||||||
|
err = ERROR_INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__TRY
|
||||||
|
{
|
||||||
|
err = svcctl_QueryServiceStatusEx(hService, InfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
|
||||||
|
}
|
||||||
|
__EXCEPT(rpc_filter)
|
||||||
|
{
|
||||||
|
err = map_exception_code(GetExceptionCode());
|
||||||
|
}
|
||||||
|
__ENDTRY
|
||||||
}
|
}
|
||||||
__ENDTRY
|
|
||||||
if (err != ERROR_SUCCESS)
|
if (err != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
SetLastError(err);
|
SetLastError(err);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -956,7 +956,6 @@ static void test_query_svc(void)
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = pQueryServiceStatusEx(NULL, 1, NULL, 0, NULL);
|
ret = pQueryServiceStatusEx(NULL, 1, NULL, 0, NULL);
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
todo_wine
|
|
||||||
ok(GetLastError() == ERROR_INVALID_LEVEL,
|
ok(GetLastError() == ERROR_INVALID_LEVEL,
|
||||||
"Expected ERROR_INVALID_LEVEL, got %d\n", GetLastError());
|
"Expected ERROR_INVALID_LEVEL, got %d\n", GetLastError());
|
||||||
|
|
||||||
|
@ -966,8 +965,8 @@ static void test_query_svc(void)
|
||||||
|
|
||||||
/* Only info level is correct. It looks like the buffer/size is checked second */
|
/* Only info level is correct. It looks like the buffer/size is checked second */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = pQueryServiceStatusEx(NULL, 0, NULL, 0, &needed);
|
ret = pQueryServiceStatusEx(NULL, SC_STATUS_PROCESS_INFO, NULL, 0, &needed);
|
||||||
/* NT4 and Wine check the handle first */
|
/* NT4 checks the handle first */
|
||||||
if (GetLastError() != ERROR_INVALID_HANDLE)
|
if (GetLastError() != ERROR_INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
|
@ -981,7 +980,7 @@ static void test_query_svc(void)
|
||||||
statusproc = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_STATUS_PROCESS));
|
statusproc = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_STATUS_PROCESS));
|
||||||
bufsize = needed;
|
bufsize = needed;
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = pQueryServiceStatusEx(NULL, 0, (BYTE*)statusproc, bufsize, &needed);
|
ret = pQueryServiceStatusEx(NULL, SC_STATUS_PROCESS_INFO, (BYTE*)statusproc, bufsize, &needed);
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
ok(GetLastError() == ERROR_INVALID_HANDLE,
|
||||||
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
||||||
|
@ -989,25 +988,22 @@ static void test_query_svc(void)
|
||||||
|
|
||||||
/* Correct handle and info level */
|
/* Correct handle and info level */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = pQueryServiceStatusEx(svc_handle, 0, NULL, 0, &needed);
|
ret = pQueryServiceStatusEx(svc_handle, SC_STATUS_PROCESS_INFO, NULL, 0, &needed);
|
||||||
/* NT4 doesn't return the needed size */
|
/* NT4 doesn't return the needed size */
|
||||||
if (GetLastError() != ERROR_INVALID_PARAMETER)
|
if (GetLastError() != ERROR_INVALID_PARAMETER)
|
||||||
{
|
{
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
todo_wine
|
|
||||||
{
|
|
||||||
ok(needed == sizeof(SERVICE_STATUS_PROCESS),
|
ok(needed == sizeof(SERVICE_STATUS_PROCESS),
|
||||||
"Needed buffersize is wrong : %d\n", needed);
|
"Needed buffersize is wrong : %d\n", needed);
|
||||||
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
||||||
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* All parameters are OK but we don't have enough rights */
|
/* All parameters are OK but we don't have enough rights */
|
||||||
statusproc = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_STATUS_PROCESS));
|
statusproc = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_STATUS_PROCESS));
|
||||||
bufsize = sizeof(SERVICE_STATUS_PROCESS);
|
bufsize = sizeof(SERVICE_STATUS_PROCESS);
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = pQueryServiceStatusEx(svc_handle, 0, (BYTE*)statusproc, bufsize, &needed);
|
ret = pQueryServiceStatusEx(svc_handle, SC_STATUS_PROCESS_INFO, (BYTE*)statusproc, bufsize, &needed);
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
ok(GetLastError() == ERROR_ACCESS_DENIED,
|
ok(GetLastError() == ERROR_ACCESS_DENIED,
|
||||||
"Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
"Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
||||||
|
@ -1021,7 +1017,7 @@ static void test_query_svc(void)
|
||||||
statusproc = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_STATUS_PROCESS));
|
statusproc = HeapAlloc(GetProcessHeap(), 0, sizeof(SERVICE_STATUS_PROCESS));
|
||||||
bufsize = sizeof(SERVICE_STATUS_PROCESS);
|
bufsize = sizeof(SERVICE_STATUS_PROCESS);
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = pQueryServiceStatusEx(svc_handle, 0, (BYTE*)statusproc, bufsize, &needed);
|
ret = pQueryServiceStatusEx(svc_handle, SC_STATUS_PROCESS_INFO, (BYTE*)statusproc, bufsize, &needed);
|
||||||
ok(ret, "Expected success, got error %u\n", GetLastError());
|
ok(ret, "Expected success, got error %u\n", GetLastError());
|
||||||
if (statusproc->dwCurrentState == SERVICE_RUNNING)
|
if (statusproc->dwCurrentState == SERVICE_RUNNING)
|
||||||
ok(statusproc->dwProcessId != 0,
|
ok(statusproc->dwProcessId != 0,
|
||||||
|
|
Loading…
Reference in New Issue