OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sys_string_conversions.h" |
8 #include "base/win/scoped_handle.h" | 9 #include "base/win/scoped_handle.h" |
9 #include "sandbox/src/sandbox.h" | 10 #include "sandbox/src/sandbox.h" |
10 #include "sandbox/src/sandbox_policy.h" | 11 #include "sandbox/src/sandbox_policy.h" |
11 #include "sandbox/src/sandbox_factory.h" | 12 #include "sandbox/src/sandbox_factory.h" |
12 #include "sandbox/src/sandbox_utils.h" | |
13 #include "sandbox/tests/common/controller.h" | 13 #include "sandbox/tests/common/controller.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // While the shell API provides better calls than this home brew function | 18 // While the shell API provides better calls than this home brew function |
19 // we use GetSystemWindowsDirectoryW which does not query the registry so | 19 // we use GetSystemWindowsDirectoryW which does not query the registry so |
20 // it is safe to use after revert. | 20 // it is safe to use after revert. |
21 std::wstring MakeFullPathToSystem32(const wchar_t* name) { | 21 std::wstring MakeFullPathToSystem32(const wchar_t* name) { |
22 wchar_t windows_path[MAX_PATH] = {0}; | 22 wchar_t windows_path[MAX_PATH] = {0}; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } else { | 60 } else { |
61 ret1 = sandbox::SBOX_TEST_SUCCEEDED; | 61 ret1 = sandbox::SBOX_TEST_SUCCEEDED; |
62 } | 62 } |
63 | 63 |
64 // Do the same with the ansi version of the api | 64 // Do the same with the ansi version of the api |
65 STARTUPINFOA sia = {sizeof(sia)}; | 65 STARTUPINFOA sia = {sizeof(sia)}; |
66 sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED; | 66 sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED; |
67 | 67 |
68 std::string narrow_cmd_line; | 68 std::string narrow_cmd_line; |
69 if (cmd_line) | 69 if (cmd_line) |
70 narrow_cmd_line = sandbox::WideToMultiByte(cmd_line); | 70 narrow_cmd_line = base::SysWideToMultiByte(cmd_line, CP_UTF8); |
71 if (!::CreateProcessA( | 71 if (!::CreateProcessA( |
72 exe_name ? sandbox::WideToMultiByte(exe_name).c_str() : NULL, | 72 exe_name ? base::SysWideToMultiByte(exe_name, CP_UTF8).c_str() : NULL, |
73 cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL, | 73 cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL, |
74 NULL, NULL, FALSE, 0, NULL, NULL, &sia, &pi)) { | 74 NULL, NULL, FALSE, 0, NULL, NULL, &sia, &pi)) { |
75 DWORD last_error = GetLastError(); | 75 DWORD last_error = GetLastError(); |
76 if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || | 76 if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || |
77 (ERROR_ACCESS_DENIED == last_error) || | 77 (ERROR_ACCESS_DENIED == last_error) || |
78 (ERROR_FILE_NOT_FOUND == last_error)) { | 78 (ERROR_FILE_NOT_FOUND == last_error)) { |
79 ret2 = sandbox::SBOX_TEST_DENIED; | 79 ret2 = sandbox::SBOX_TEST_DENIED; |
80 } else { | 80 } else { |
81 ret2 = sandbox::SBOX_TEST_FAILED; | 81 ret2 = sandbox::SBOX_TEST_FAILED; |
82 } | 82 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 ASSERT_TRUE(!exe_path.empty()); | 285 ASSERT_TRUE(!exe_path.empty()); |
286 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS, | 286 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS, |
287 TargetPolicy::PROCESS_ALL_EXEC, | 287 TargetPolicy::PROCESS_ALL_EXEC, |
288 exe_path.c_str())); | 288 exe_path.c_str())); |
289 | 289 |
290 EXPECT_EQ(SBOX_TEST_SUCCEEDED, | 290 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
291 runner.RunTest(L"Process_GetChildProcessToken findstr.exe")); | 291 runner.RunTest(L"Process_GetChildProcessToken findstr.exe")); |
292 } | 292 } |
293 | 293 |
294 } // namespace sandbox | 294 } // namespace sandbox |
OLD | NEW |