| 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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "base/win/scoped_handle.h" | 6 #include "base/win/scoped_handle.h" |
| 7 #include "sandbox/win/src/handle_closer_agent.h" | 7 #include "sandbox/win/src/handle_closer_agent.h" |
| 8 #include "sandbox/win/src/sandbox.h" | 8 #include "sandbox/win/src/sandbox.h" |
| 9 #include "sandbox/win/src/sandbox_factory.h" | 9 #include "sandbox/win/src/sandbox_factory.h" |
| 10 #include "sandbox/win/src/target_services.h" | 10 #include "sandbox/win/src/target_services.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 base::string16 marker_path = path_buffer; | 22 base::string16 marker_path = path_buffer; |
| 23 marker_path += L"\\sbox_marker_"; | 23 marker_path += L"\\sbox_marker_"; |
| 24 | 24 |
| 25 // Generate a unique value from the exe's size and timestamp. | 25 // Generate a unique value from the exe's size and timestamp. |
| 26 CHECK(::GetModuleFileName(NULL, path_buffer, MAX_PATH)); | 26 CHECK(::GetModuleFileName(NULL, path_buffer, MAX_PATH)); |
| 27 base::win::ScopedHandle module(::CreateFile(path_buffer, | 27 base::win::ScopedHandle module(::CreateFile(path_buffer, |
| 28 FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, | 28 FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, |
| 29 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); | 29 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); |
| 30 CHECK(module.IsValid()); | 30 CHECK(module.IsValid()); |
| 31 FILETIME timestamp; | 31 FILETIME timestamp; |
| 32 CHECK(::GetFileTime(module, ×tamp, NULL, NULL)); | 32 CHECK(::GetFileTime(module.Get(), ×tamp, NULL, NULL)); |
| 33 marker_path += base::StringPrintf(L"%08x%08x%08x", | 33 marker_path += base::StringPrintf(L"%08x%08x%08x", |
| 34 ::GetFileSize(module, NULL), | 34 ::GetFileSize(module.Get(), NULL), |
| 35 timestamp.dwLowDateTime, | 35 timestamp.dwLowDateTime, |
| 36 timestamp.dwHighDateTime); | 36 timestamp.dwHighDateTime); |
| 37 marker_path += extension; | 37 marker_path += extension; |
| 38 | 38 |
| 39 // Make the file delete-on-close so cleanup is automatic. | 39 // Make the file delete-on-close so cleanup is automatic. |
| 40 return CreateFile(marker_path.c_str(), FILE_ALL_ACCESS, | 40 return CreateFile(marker_path.c_str(), FILE_ALL_ACCESS, |
| 41 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 41 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 42 NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); | 42 NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); |
| 43 } | 43 } |
| 44 | 44 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 TestRunner runner; | 108 TestRunner runner; |
| 109 runner.SetTimeout(2000); | 109 runner.SetTimeout(2000); |
| 110 runner.SetTestState(EVERY_STATE); | 110 runner.SetTestState(EVERY_STATE); |
| 111 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 111 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
| 112 | 112 |
| 113 base::string16 command = base::string16(L"CheckForFileHandles Y"); | 113 base::string16 command = base::string16(L"CheckForFileHandles Y"); |
| 114 for (int i = 0; i < arraysize(kFileExtensions); ++i) { | 114 for (int i = 0; i < arraysize(kFileExtensions); ++i) { |
| 115 base::string16 handle_name; | 115 base::string16 handle_name; |
| 116 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); | 116 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); |
| 117 CHECK(marker.IsValid()); | 117 CHECK(marker.IsValid()); |
| 118 CHECK(sandbox::GetHandleName(marker, &handle_name)); | 118 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name)); |
| 119 command += (L" "); | 119 command += (L" "); |
| 120 command += handle_name; | 120 command += handle_name; |
| 121 } | 121 } |
| 122 | 122 |
| 123 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) << | 123 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) << |
| 124 "Failed: " << command; | 124 "Failed: " << command; |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST(HandleCloserTest, CloseMarkerFiles) { | 127 TEST(HandleCloserTest, CloseMarkerFiles) { |
| 128 TestRunner runner; | 128 TestRunner runner; |
| 129 runner.SetTimeout(2000); | 129 runner.SetTimeout(2000); |
| 130 runner.SetTestState(EVERY_STATE); | 130 runner.SetTestState(EVERY_STATE); |
| 131 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 131 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
| 132 | 132 |
| 133 base::string16 command = base::string16(L"CheckForFileHandles N"); | 133 base::string16 command = base::string16(L"CheckForFileHandles N"); |
| 134 for (int i = 0; i < arraysize(kFileExtensions); ++i) { | 134 for (int i = 0; i < arraysize(kFileExtensions); ++i) { |
| 135 base::string16 handle_name; | 135 base::string16 handle_name; |
| 136 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); | 136 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); |
| 137 CHECK(marker.IsValid()); | 137 CHECK(marker.IsValid()); |
| 138 CHECK(sandbox::GetHandleName(marker, &handle_name)); | 138 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name)); |
| 139 CHECK_EQ(policy->AddKernelObjectToClose(L"File", handle_name.c_str()), | 139 CHECK_EQ(policy->AddKernelObjectToClose(L"File", handle_name.c_str()), |
| 140 SBOX_ALL_OK); | 140 SBOX_ALL_OK); |
| 141 command += (L" "); | 141 command += (L" "); |
| 142 command += handle_name; | 142 command += handle_name; |
| 143 } | 143 } |
| 144 | 144 |
| 145 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) << | 145 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) << |
| 146 "Failed: " << command; | 146 "Failed: " << command; |
| 147 } | 147 } |
| 148 | 148 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 runner.SetTestState(AFTER_REVERT); | 186 runner.SetTestState(AFTER_REVERT); |
| 187 sandbox::TargetPolicy* policy = runner.GetPolicy(); | 187 sandbox::TargetPolicy* policy = runner.GetPolicy(); |
| 188 | 188 |
| 189 // Sever the CSRSS connection by closing ALPC ports inside the sandbox. | 189 // Sever the CSRSS connection by closing ALPC ports inside the sandbox. |
| 190 CHECK_EQ(policy->AddKernelObjectToClose(L"ALPC Port", NULL), SBOX_ALL_OK); | 190 CHECK_EQ(policy->AddKernelObjectToClose(L"ALPC Port", NULL), SBOX_ALL_OK); |
| 191 | 191 |
| 192 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"RunThreadPool")); | 192 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"RunThreadPool")); |
| 193 } | 193 } |
| 194 | 194 |
| 195 } // namespace sandbox | 195 } // namespace sandbox |
| OLD | NEW |