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

Side by Side Diff: chrome/installer/util/product.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/util/product.h" 5 #include "chrome/installer/util/product.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 #include "base/win/scoped_process_information.h"
13 #include "chrome/installer/util/chrome_browser_operations.h" 14 #include "chrome/installer/util/chrome_browser_operations.h"
14 #include "chrome/installer/util/chrome_browser_sxs_operations.h" 15 #include "chrome/installer/util/chrome_browser_sxs_operations.h"
15 #include "chrome/installer/util/chrome_frame_operations.h" 16 #include "chrome/installer/util/chrome_frame_operations.h"
16 #include "chrome/installer/util/google_update_constants.h" 17 #include "chrome/installer/util/google_update_constants.h"
17 #include "chrome/installer/util/helper.h" 18 #include "chrome/installer/util/helper.h"
18 #include "chrome/installer/util/install_util.h" 19 #include "chrome/installer/util/install_util.h"
19 #include "chrome/installer/util/master_preferences.h" 20 #include "chrome/installer/util/master_preferences.h"
20 #include "chrome/installer/util/master_preferences_constants.h" 21 #include "chrome/installer/util/master_preferences_constants.h"
21 #include "chrome/installer/util/product_operations.h" 22 #include "chrome/installer/util/product_operations.h"
22 23
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const CommandLine& options, 72 const CommandLine& options,
72 int32* exit_code) const { 73 int32* exit_code) const {
73 if (application_path.empty()) 74 if (application_path.empty())
74 return false; 75 return false;
75 76
76 CommandLine cmd(application_path.Append(installer::kChromeExe)); 77 CommandLine cmd(application_path.Append(installer::kChromeExe));
77 cmd.AppendArguments(options, false); 78 cmd.AppendArguments(options, false);
78 79
79 bool success = false; 80 bool success = false;
80 STARTUPINFOW si = { sizeof(si) }; 81 STARTUPINFOW si = { sizeof(si) };
81 PROCESS_INFORMATION pi = {0}; 82 base::win::ScopedProcessInformation pi;
82 // Create a writable copy of the command line string, since CreateProcess may 83 // Create a writable copy of the command line string, since CreateProcess may
83 // modify the string (insert \0 to separate the program from the arguments). 84 // modify the string (insert \0 to separate the program from the arguments).
84 std::wstring writable_command_line_string(cmd.GetCommandLineString()); 85 std::wstring writable_command_line_string(cmd.GetCommandLineString());
85 if (!::CreateProcess(cmd.GetProgram().value().c_str(), 86 if (!::CreateProcess(cmd.GetProgram().value().c_str(),
86 &writable_command_line_string[0], 87 &writable_command_line_string[0],
87 NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, 88 NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL,
88 &si, &pi)) { 89 &si, pi.Receive())) {
89 PLOG(ERROR) << "Failed to launch: " << cmd.GetCommandLineString(); 90 PLOG(ERROR) << "Failed to launch: " << cmd.GetCommandLineString();
90 } else { 91 } else {
91 ::CloseHandle(pi.hThread); 92 DWORD ret = ::WaitForSingleObject(pi.Get().hProcess, INFINITE);
92
93 DWORD ret = ::WaitForSingleObject(pi.hProcess, INFINITE);
94 DLOG_IF(ERROR, ret != WAIT_OBJECT_0) 93 DLOG_IF(ERROR, ret != WAIT_OBJECT_0)
95 << "Unexpected return value from WaitForSingleObject: " << ret; 94 << "Unexpected return value from WaitForSingleObject: " << ret;
96 if (::GetExitCodeProcess(pi.hProcess, &ret)) { 95 if (::GetExitCodeProcess(pi.Get().hProcess, &ret)) {
97 DCHECK(ret != STILL_ACTIVE); 96 DCHECK(ret != STILL_ACTIVE);
98 success = true; 97 success = true;
99 if (exit_code) 98 if (exit_code)
100 *exit_code = ret; 99 *exit_code = ret;
101 } else { 100 } else {
102 PLOG(ERROR) << "GetExitCodeProcess failed"; 101 PLOG(ERROR) << "GetExitCodeProcess failed";
103 } 102 }
104
105 ::CloseHandle(pi.hProcess);
106 } 103 }
107 104
108 return success; 105 return success;
109 } 106 }
110 107
111 bool Product::SetMsiMarker(bool system_install, bool set) const { 108 bool Product::SetMsiMarker(bool system_install, bool set) const {
112 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 109 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
113 RegKey client_state_key; 110 RegKey client_state_key;
114 LONG result = client_state_key.Open(reg_root, 111 LONG result = client_state_key.Open(reg_root,
115 distribution_->GetStateKey().c_str(), KEY_READ | KEY_WRITE); 112 distribution_->GetStateKey().c_str(), KEY_READ | KEY_WRITE);
(...skipping 26 matching lines...) Expand all
142 139
143 void Product::AppendRenameFlags(CommandLine* command_line) const { 140 void Product::AppendRenameFlags(CommandLine* command_line) const {
144 operations_->AppendRenameFlags(options_, command_line); 141 operations_->AppendRenameFlags(options_, command_line);
145 } 142 }
146 143
147 bool Product::SetChannelFlags(bool set, ChannelInfo* channel_info) const { 144 bool Product::SetChannelFlags(bool set, ChannelInfo* channel_info) const {
148 return operations_->SetChannelFlags(options_, set, channel_info); 145 return operations_->SetChannelFlags(options_, set, channel_info);
149 } 146 }
150 147
151 } // namespace installer 148 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698