Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(918)

Unified Diff: sandbox/src/process_policy_test.cc

Issue 9959018: Use ScopedProcessInformation and other RAII types in sandbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another potentially leaked HANDLE. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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())) {
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())) {
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)

Powered by Google App Engine
This is Rietveld 408576698