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

Side by Side Diff: sandbox/win/src/process_policy_test.cc

Issue 71013004: Base: Remove Receive() from ScopedHandle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix delegate_execute for google_chrome_build Created 7 years 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
« no previous file with comments | « sandbox/win/src/policy_target_test.cc ('k') | sandbox/win/src/restricted_token_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/win/scoped_handle.h" 10 #include "base/win/scoped_handle.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const wchar_t *exe_name = NULL; 43 const wchar_t *exe_name = NULL;
44 if (!exe.empty()) 44 if (!exe.empty())
45 exe_name = exe.c_str(); 45 exe_name = exe.c_str();
46 46
47 const wchar_t *cmd_line = NULL; 47 const wchar_t *cmd_line = NULL;
48 if (!command.empty()) 48 if (!command.empty())
49 cmd_line = command.c_str(); 49 cmd_line = command.c_str();
50 50
51 // Create the process with the unicode version of the API. 51 // Create the process with the unicode version of the API.
52 sandbox::SboxTestResult ret1 = sandbox::SBOX_TEST_FAILED; 52 sandbox::SboxTestResult ret1 = sandbox::SBOX_TEST_FAILED;
53 if (!::CreateProcessW(exe_name, const_cast<wchar_t*>(cmd_line), NULL, NULL, 53 PROCESS_INFORMATION temp_process_info = {};
54 FALSE, 0, NULL, NULL, &si, pi.Receive())) { 54 if (::CreateProcessW(exe_name, const_cast<wchar_t*>(cmd_line), NULL, NULL,
55 FALSE, 0, NULL, NULL, &si, &temp_process_info)) {
56 pi.Set(temp_process_info);
57 ret1 = sandbox::SBOX_TEST_SUCCEEDED;
58 } else {
55 DWORD last_error = GetLastError(); 59 DWORD last_error = GetLastError();
56 if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || 60 if ((ERROR_NOT_ENOUGH_QUOTA == last_error) ||
57 (ERROR_ACCESS_DENIED == last_error) || 61 (ERROR_ACCESS_DENIED == last_error) ||
58 (ERROR_FILE_NOT_FOUND == last_error)) { 62 (ERROR_FILE_NOT_FOUND == last_error)) {
59 ret1 = sandbox::SBOX_TEST_DENIED; 63 ret1 = sandbox::SBOX_TEST_DENIED;
60 } else { 64 } else {
61 ret1 = sandbox::SBOX_TEST_FAILED; 65 ret1 = sandbox::SBOX_TEST_FAILED;
62 } 66 }
63 } else {
64 ret1 = sandbox::SBOX_TEST_SUCCEEDED;
65 } 67 }
66 68
67 pi.Close(); 69 pi.Close();
68 70
69 // Do the same with the ansi version of the api 71 // Do the same with the ansi version of the api
70 STARTUPINFOA sia = {sizeof(sia)}; 72 STARTUPINFOA sia = {sizeof(sia)};
71 sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED; 73 sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED;
72 74
73 std::string narrow_cmd_line; 75 std::string narrow_cmd_line;
74 if (cmd_line) 76 if (cmd_line)
75 narrow_cmd_line = base::SysWideToMultiByte(cmd_line, CP_UTF8); 77 narrow_cmd_line = base::SysWideToMultiByte(cmd_line, CP_UTF8);
76 if (!::CreateProcessA( 78 if (::CreateProcessA(
77 exe_name ? base::SysWideToMultiByte(exe_name, CP_UTF8).c_str() : NULL, 79 exe_name ? base::SysWideToMultiByte(exe_name, CP_UTF8).c_str() : NULL,
78 cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL, 80 cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL,
79 NULL, NULL, FALSE, 0, NULL, NULL, &sia, pi.Receive())) { 81 NULL, NULL, FALSE, 0, NULL, NULL, &sia, &temp_process_info)) {
82 pi.Set(temp_process_info);
83 ret2 = sandbox::SBOX_TEST_SUCCEEDED;
84 } else {
80 DWORD last_error = GetLastError(); 85 DWORD last_error = GetLastError();
81 if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || 86 if ((ERROR_NOT_ENOUGH_QUOTA == last_error) ||
82 (ERROR_ACCESS_DENIED == last_error) || 87 (ERROR_ACCESS_DENIED == last_error) ||
83 (ERROR_FILE_NOT_FOUND == last_error)) { 88 (ERROR_FILE_NOT_FOUND == last_error)) {
84 ret2 = sandbox::SBOX_TEST_DENIED; 89 ret2 = sandbox::SBOX_TEST_DENIED;
85 } else { 90 } else {
86 ret2 = sandbox::SBOX_TEST_FAILED; 91 ret2 = sandbox::SBOX_TEST_FAILED;
87 } 92 }
88 } else {
89 ret2 = sandbox::SBOX_TEST_SUCCEEDED;
90 } 93 }
91 94
92 if (ret1 == ret2) 95 if (ret1 == ret2)
93 return ret1; 96 return ret1;
94 97
95 return sandbox::SBOX_TEST_FAILED; 98 return sandbox::SBOX_TEST_FAILED;
96 } 99 }
97 100
98 } // namespace 101 } // namespace
99 102
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // Creates a process and checks if it's possible to get a handle to it's token. 211 // Creates a process and checks if it's possible to get a handle to it's token.
209 SBOX_TESTS_COMMAND int Process_GetChildProcessToken(int argc, wchar_t **argv) { 212 SBOX_TESTS_COMMAND int Process_GetChildProcessToken(int argc, wchar_t **argv) {
210 if (argc != 1) 213 if (argc != 1)
211 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 214 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
212 215
213 if ((NULL == argv) || (NULL == argv[0])) 216 if ((NULL == argv) || (NULL == argv[0]))
214 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 217 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
215 218
216 string16 path = MakeFullPathToSystem32(argv[0]); 219 string16 path = MakeFullPathToSystem32(argv[0]);
217 220
218 base::win::ScopedProcessInformation pi;
219 STARTUPINFOW si = {sizeof(si)}; 221 STARTUPINFOW si = {sizeof(si)};
220 222
223 PROCESS_INFORMATION temp_process_info = {};
221 if (!::CreateProcessW(path.c_str(), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, 224 if (!::CreateProcessW(path.c_str(), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED,
222 NULL, NULL, &si, pi.Receive())) { 225 NULL, NULL, &si, &temp_process_info)) {
223 return SBOX_TEST_FAILED; 226 return SBOX_TEST_FAILED;
224 } 227 }
228 base::win::ScopedProcessInformation pi(temp_process_info);
225 229
226 HANDLE token = NULL; 230 HANDLE token = NULL;
227 BOOL result = 231 BOOL result =
228 ::OpenProcessToken(pi.process_handle(), TOKEN_IMPERSONATE, &token); 232 ::OpenProcessToken(pi.process_handle(), TOKEN_IMPERSONATE, &token);
229 DWORD error = ::GetLastError(); 233 DWORD error = ::GetLastError();
230 234
231 base::win::ScopedHandle token_handle(token); 235 base::win::ScopedHandle token_handle(token);
232 236
233 if (!::TerminateProcess(pi.process_handle(), 0)) 237 if (!::TerminateProcess(pi.process_handle(), 0))
234 return SBOX_TEST_FAILED; 238 return SBOX_TEST_FAILED;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 ASSERT_TRUE(!exe_path.empty()); 379 ASSERT_TRUE(!exe_path.empty());
376 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS, 380 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS,
377 TargetPolicy::PROCESS_ALL_EXEC, 381 TargetPolicy::PROCESS_ALL_EXEC,
378 exe_path.c_str())); 382 exe_path.c_str()));
379 383
380 EXPECT_EQ(SBOX_TEST_SUCCEEDED, 384 EXPECT_EQ(SBOX_TEST_SUCCEEDED,
381 runner.RunTest(L"Process_GetChildProcessToken findstr.exe")); 385 runner.RunTest(L"Process_GetChildProcessToken findstr.exe"));
382 } 386 }
383 387
384 } // namespace sandbox 388 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/policy_target_test.cc ('k') | sandbox/win/src/restricted_token_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698