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

Unified Diff: sandbox/src/restricted_token_utils.cc

Issue 9700038: ScopedProcessInformation protects against process/thread handle leaks from CreateProcess calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove changes from another CL. 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/restricted_token_utils.cc
diff --git a/sandbox/src/restricted_token_utils.cc b/sandbox/src/restricted_token_utils.cc
index b036e51e665612632be57e9d63144aea987c4462..3ba24f3ab3931398b605753e6c5687881fc6557b 100644
--- a/sandbox/src/restricted_token_utils.cc
+++ b/sandbox/src/restricted_token_utils.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/win/scoped_handle.h"
+#include "base/win/scoped_process_information.h"
#include "base/win/windows_version.h"
#include "sandbox/src/job.h"
#include "sandbox/src/restricted_token.h"
@@ -182,7 +183,7 @@ DWORD StartRestrictedProcessInJob(wchar_t *command_line,
// Start the process
STARTUPINFO startup_info = {0};
- PROCESS_INFORMATION process_info = {0};
+ base::win::ScopedProcessInformation process_info;
if (!::CreateProcessAsUser(primary_token.Get(),
NULL, // No application name.
@@ -194,30 +195,30 @@ DWORD StartRestrictedProcessInJob(wchar_t *command_line,
NULL, // Use the environment of the caller.
NULL, // Use current directory of the caller.
&startup_info,
- &process_info)) {
+ process_info.Receive())) {
return ::GetLastError();
}
- base::win::ScopedHandle thread_handle(process_info.hThread);
- base::win::ScopedHandle process_handle(process_info.hProcess);
-
// Change the token of the main thread of the new process for the
// impersonation token with more rights.
- if (!::SetThreadToken(&process_info.hThread, impersonation_token.Get())) {
- ::TerminateProcess(process_handle.Get(),
- 0); // exit code
- return ::GetLastError();
+ {
+ HANDLE temp_thread = process_info.Get().hThread;
+ if (!::SetThreadToken(&temp_thread, impersonation_token.Get())) {
+ ::TerminateProcess(process_info.Get().hProcess,
+ 0); // exit code
+ return ::GetLastError();
+ }
}
- err_code = job.AssignProcessToJob(process_handle.Get());
+ err_code = job.AssignProcessToJob(process_info.Get().hProcess);
if (ERROR_SUCCESS != err_code) {
- ::TerminateProcess(process_handle.Get(),
+ ::TerminateProcess(process_info.Get().hProcess,
0); // exit code
return ::GetLastError();
}
// Start the application
- ::ResumeThread(thread_handle.Get());
+ ::ResumeThread(process_info.Get().hThread);
(*job_handle_ret) = job.Detach();

Powered by Google App Engine
This is Rietveld 408576698