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

Unified Diff: sandbox/src/broker_services.cc

Issue 10493002: Revert 130716 - Use ScopedProcessInformation and other RAII types in sandbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
« no previous file with comments | « sandbox/src/Wow64.cc ('k') | sandbox/src/interception_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/src/broker_services.cc
===================================================================
--- sandbox/src/broker_services.cc (revision 140102)
+++ sandbox/src/broker_services.cc (working copy)
@@ -5,10 +5,7 @@
#include "sandbox/src/broker_services.h"
#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
#include "base/threading/platform_thread.h"
-#include "base/win/scoped_handle.h"
-#include "base/win/scoped_process_information.h"
#include "sandbox/src/sandbox_policy_base.h"
#include "sandbox/src/sandbox.h"
#include "sandbox/src/target_process.h"
@@ -297,15 +294,14 @@
// Construct the tokens and the job object that we are going to associate
// with the soon to be created target process.
- base::win::ScopedHandle lockdown_token;
- base::win::ScopedHandle initial_token;
- DWORD win_result = policy_base->MakeTokens(initial_token.Receive(),
- lockdown_token.Receive());
+ HANDLE lockdown_token = NULL;
+ HANDLE initial_token = NULL;
+ DWORD win_result = policy_base->MakeTokens(&initial_token, &lockdown_token);
if (ERROR_SUCCESS != win_result)
return SBOX_ERROR_GENERIC;
- base::win::ScopedHandle job;
- win_result = policy_base->MakeJobObject(job.Receive());
+ HANDLE job = NULL;
+ win_result = policy_base->MakeJobObject(&job);
if (ERROR_SUCCESS != win_result)
return SBOX_ERROR_GENERIC;
@@ -319,11 +315,9 @@
// Create the TargetProces object and spawn the target suspended. Note that
// Brokerservices does not own the target object. It is owned by the Policy.
- base::win::ScopedProcessInformation process_info;
- TargetProcess* target = new TargetProcess(initial_token.Take(),
- lockdown_token.Take(),
- job,
- thread_pool_);
+ PROCESS_INFORMATION process_info = {0};
+ TargetProcess* target = new TargetProcess(initial_token, lockdown_token,
+ job, thread_pool_);
std::wstring desktop = policy_base->GetAlternateDesktop();
@@ -333,6 +327,10 @@
if (ERROR_SUCCESS != win_result)
return SpawnCleanup(target, win_result);
+ if ((INVALID_HANDLE_VALUE == process_info.hProcess) ||
+ (INVALID_HANDLE_VALUE == process_info.hThread))
+ return SpawnCleanup(target, win_result);
+
// Now the policy is the owner of the target.
if (!policy_base->AddTarget(target)) {
return SpawnCleanup(target, 0);
@@ -341,15 +339,24 @@
// We are going to keep a pointer to the policy because we'll call it when
// the job object generates notifications using the completion port.
policy_base->AddRef();
- scoped_ptr<JobTracker> tracker(new JobTracker(job.Take(), policy_base));
- if (!AssociateCompletionPort(tracker->job, job_port_, tracker.get()))
+ JobTracker* tracker = new JobTracker(job, policy_base);
+ if (!AssociateCompletionPort(job, job_port_, tracker))
return SpawnCleanup(target, 0);
// Save the tracker because in cleanup we might need to force closing
// the Jobs.
- tracker_list_.push_back(tracker.release());
- child_process_ids_.insert(process_info.process_id());
+ tracker_list_.push_back(tracker);
+ child_process_ids_.insert(process_info.dwProcessId);
- *target_info = process_info.Take();
+ // We return the caller a duplicate of the process handle so they
+ // can close it at will.
+ HANDLE dup_process_handle = NULL;
+ if (!::DuplicateHandle(::GetCurrentProcess(), process_info.hProcess,
+ ::GetCurrentProcess(), &dup_process_handle,
+ 0, FALSE, DUPLICATE_SAME_ACCESS))
+ return SpawnCleanup(target, 0);
+
+ *target_info = process_info;
+ target_info->hProcess = dup_process_handle;
return SBOX_ALL_OK;
}
« no previous file with comments | « sandbox/src/Wow64.cc ('k') | sandbox/src/interception_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698