Chromium Code Reviews| Index: sandbox/src/process_policy_test.cc |
| diff --git a/sandbox/src/process_policy_test.cc b/sandbox/src/process_policy_test.cc |
| index 1bcfa887208477ba1da3511dbd1e043be291471f..45e7aae11708f796fc4429a710446d794d715fb3 100644 |
| --- a/sandbox/src/process_policy_test.cc |
| +++ b/sandbox/src/process_policy_test.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/sys_string_conversions.h" |
| #include "base/win/scoped_handle.h" |
| +#include "base/win/scoped_process_information.h" |
| #include "sandbox/src/sandbox.h" |
| #include "sandbox/src/sandbox_policy.h" |
| #include "sandbox/src/sandbox_factory.h" |
| @@ -34,7 +35,7 @@ std::wstring MakeFullPathToSystem32(const wchar_t* name) { |
| // unicode and ascii version of the api. |
| sandbox::SboxTestResult CreateProcessHelper(const std::wstring &exe, |
| const std::wstring &command) { |
| - PROCESS_INFORMATION pi; |
| + base::win::ScopedProcessInformation pi; |
| STARTUPINFOW si = {sizeof(si)}; |
| const wchar_t *exe_name = NULL; |
| @@ -48,7 +49,7 @@ sandbox::SboxTestResult CreateProcessHelper(const std::wstring &exe, |
| // Create the process with the unicode version of the API. |
| sandbox::SboxTestResult ret1 = sandbox::SBOX_TEST_FAILED; |
| if (!::CreateProcessW(exe_name, const_cast<wchar_t*>(cmd_line), NULL, NULL, |
| - FALSE, 0, NULL, NULL, &si, &pi)) { |
| + FALSE, 0, NULL, NULL, &si, pi.Receive())) { |
|
erikwright (departed)
2012/03/30 16:29:31
Previously leaked handles.
|
| DWORD last_error = GetLastError(); |
| if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || |
| (ERROR_ACCESS_DENIED == last_error) || |
| @@ -61,6 +62,8 @@ sandbox::SboxTestResult CreateProcessHelper(const std::wstring &exe, |
| ret1 = sandbox::SBOX_TEST_SUCCEEDED; |
| } |
| + pi.Close(); |
| + |
| // Do the same with the ansi version of the api |
| STARTUPINFOA sia = {sizeof(sia)}; |
| sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED; |
| @@ -71,7 +74,7 @@ sandbox::SboxTestResult CreateProcessHelper(const std::wstring &exe, |
| if (!::CreateProcessA( |
| exe_name ? base::SysWideToMultiByte(exe_name, CP_UTF8).c_str() : NULL, |
| cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL, |
| - NULL, NULL, FALSE, 0, NULL, NULL, &sia, &pi)) { |
| + NULL, NULL, FALSE, 0, NULL, NULL, &sia, pi.Receive())) { |
|
erikwright (departed)
2012/03/30 16:29:31
ditto.
|
| DWORD last_error = GetLastError(); |
| if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || |
| (ERROR_ACCESS_DENIED == last_error) || |
| @@ -170,24 +173,22 @@ SBOX_TESTS_COMMAND int Process_GetChildProcessToken(int argc, wchar_t **argv) { |
| std::wstring path = MakeFullPathToSystem32(argv[0]); |
| - PROCESS_INFORMATION pi = {0}; |
| + base::win::ScopedProcessInformation pi; |
| STARTUPINFOW si = {sizeof(si)}; |
| if (!::CreateProcessW(path.c_str(), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, |
| - NULL, NULL, &si, &pi)) { |
| + NULL, NULL, &si, pi.Receive())) { |
| return SBOX_TEST_FAILED; |
| } |
| - base::win::ScopedHandle process(pi.hProcess); |
| - base::win::ScopedHandle thread(pi.hThread); |
| - |
| HANDLE token = NULL; |
| - BOOL result = ::OpenProcessToken(process.Get(), TOKEN_IMPERSONATE, &token); |
| + BOOL result = |
| + ::OpenProcessToken(pi.process_handle(), TOKEN_IMPERSONATE, &token); |
| DWORD error = ::GetLastError(); |
| base::win::ScopedHandle token_handle(token); |
| - if (!::TerminateProcess(process.Get(), 0)) |
| + if (!::TerminateProcess(pi.process_handle(), 0)) |
| return SBOX_TEST_FAILED; |
| if (result && token) |