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

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

Issue 1507413003: clang/win: Let some chromium_code targets build with -Wextra. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: content_browsertests Created 5 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
« no previous file with comments | « sandbox/win/src/crosscall_params.h ('k') | sandbox/win/src/interception_unittest.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) 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/nt_internals.h" 8 #include "sandbox/win/src/nt_internals.h"
9 #include "sandbox/win/src/sandbox.h" 9 #include "sandbox/win/src/sandbox.h"
10 #include "sandbox/win/src/sandbox_factory.h" 10 #include "sandbox/win/src/sandbox_factory.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return SBOX_TEST_FAILED_TO_RUN_TEST; 79 return SBOX_TEST_FAILED_TO_RUN_TEST;
80 bool should_find = argv[0][0] == L'Y'; 80 bool should_find = argv[0][0] == L'Y';
81 if (argv[0][1] != L'\0' || (!should_find && argv[0][0] != L'N')) 81 if (argv[0][1] != L'\0' || (!should_find && argv[0][0] != L'N'))
82 return SBOX_TEST_FAILED_TO_RUN_TEST; 82 return SBOX_TEST_FAILED_TO_RUN_TEST;
83 83
84 static int state = BEFORE_INIT; 84 static int state = BEFORE_INIT;
85 switch (state++) { 85 switch (state++) {
86 case BEFORE_INIT: 86 case BEFORE_INIT:
87 // Create a unique marker file that is open while the test is running. 87 // Create a unique marker file that is open while the test is running.
88 // The handles leak, but it will be closed by the test or on exit. 88 // The handles leak, but it will be closed by the test or on exit.
89 for (int i = 0; i < arraysize(kFileExtensions); ++i) 89 for (const wchar_t* kExtension : kFileExtensions)
90 CHECK_NE(GetMarkerFile(kFileExtensions[i]), INVALID_HANDLE_VALUE); 90 CHECK_NE(GetMarkerFile(kExtension), INVALID_HANDLE_VALUE);
91 return SBOX_TEST_SUCCEEDED; 91 return SBOX_TEST_SUCCEEDED;
92 92
93 case AFTER_REVERT: { 93 case AFTER_REVERT: {
94 // Brute force the handle table to find what we're looking for. 94 // Brute force the handle table to find what we're looking for.
95 DWORD handle_count = UINT_MAX; 95 DWORD handle_count = UINT_MAX;
96 const int kInvalidHandleThreshold = 100; 96 const int kInvalidHandleThreshold = 100;
97 const size_t kHandleOffset = 4; // Handles are always a multiple of 4. 97 const size_t kHandleOffset = 4; // Handles are always a multiple of 4.
98 HANDLE handle = NULL; 98 HANDLE handle = NULL;
99 int invalid_count = 0; 99 int invalid_count = 0;
100 base::string16 handle_name; 100 base::string16 handle_name;
(...skipping 26 matching lines...) Expand all
127 127
128 // Checks that supplied handle is an Event and it's not waitable. 128 // Checks that supplied handle is an Event and it's not waitable.
129 // Format: CheckForEventHandles 129 // Format: CheckForEventHandles
130 SBOX_TESTS_COMMAND int CheckForEventHandles(int argc, wchar_t** argv) { 130 SBOX_TESTS_COMMAND int CheckForEventHandles(int argc, wchar_t** argv) {
131 static int state = BEFORE_INIT; 131 static int state = BEFORE_INIT;
132 static std::vector<HANDLE> to_check; 132 static std::vector<HANDLE> to_check;
133 133
134 switch (state++) { 134 switch (state++) {
135 case BEFORE_INIT: 135 case BEFORE_INIT:
136 // Create a unique marker file that is open while the test is running. 136 // Create a unique marker file that is open while the test is running.
137 for (int i = 0; i < arraysize(kFileExtensions); ++i) { 137 for (const wchar_t* kExtension : kFileExtensions) {
138 HANDLE handle = GetMarkerFile(kFileExtensions[i]); 138 HANDLE handle = GetMarkerFile(kExtension);
139 CHECK_NE(handle, INVALID_HANDLE_VALUE); 139 CHECK_NE(handle, INVALID_HANDLE_VALUE);
140 to_check.push_back(handle); 140 to_check.push_back(handle);
141 } 141 }
142 return SBOX_TEST_SUCCEEDED; 142 return SBOX_TEST_SUCCEEDED;
143 143
144 case AFTER_REVERT: 144 case AFTER_REVERT:
145 for (auto handle : to_check) { 145 for (auto handle : to_check) {
146 // Set up buffers for the type info and the name. 146 // Set up buffers for the type info and the name.
147 std::vector<BYTE> type_info_buffer(sizeof(OBJECT_TYPE_INFORMATION) + 147 std::vector<BYTE> type_info_buffer(sizeof(OBJECT_TYPE_INFORMATION) +
148 32 * sizeof(wchar_t)); 148 32 * sizeof(wchar_t));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 return SBOX_TEST_SUCCEEDED; 189 return SBOX_TEST_SUCCEEDED;
190 } 190 }
191 191
192 TEST(HandleCloserTest, CheckForMarkerFiles) { 192 TEST(HandleCloserTest, CheckForMarkerFiles) {
193 TestRunner runner; 193 TestRunner runner;
194 runner.SetTimeout(2000); 194 runner.SetTimeout(2000);
195 runner.SetTestState(EVERY_STATE); 195 runner.SetTestState(EVERY_STATE);
196 196
197 base::string16 command = base::string16(L"CheckForFileHandles Y"); 197 base::string16 command = base::string16(L"CheckForFileHandles Y");
198 for (int i = 0; i < arraysize(kFileExtensions); ++i) { 198 for (const wchar_t* kExtension : kFileExtensions) {
199 base::string16 handle_name; 199 base::string16 handle_name;
200 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); 200 base::win::ScopedHandle marker(GetMarkerFile(kExtension));
201 CHECK(marker.IsValid()); 201 CHECK(marker.IsValid());
202 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name)); 202 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name));
203 command += (L" "); 203 command += (L" ");
204 command += handle_name; 204 command += handle_name;
205 } 205 }
206 206
207 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) << 207 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) <<
208 "Failed: " << command; 208 "Failed: " << command;
209 } 209 }
210 210
211 TEST(HandleCloserTest, CloseMarkerFiles) { 211 TEST(HandleCloserTest, CloseMarkerFiles) {
212 TestRunner runner; 212 TestRunner runner;
213 runner.SetTimeout(2000); 213 runner.SetTimeout(2000);
214 runner.SetTestState(EVERY_STATE); 214 runner.SetTestState(EVERY_STATE);
215 sandbox::TargetPolicy* policy = runner.GetPolicy(); 215 sandbox::TargetPolicy* policy = runner.GetPolicy();
216 216
217 base::string16 command = base::string16(L"CheckForFileHandles N"); 217 base::string16 command = base::string16(L"CheckForFileHandles N");
218 for (int i = 0; i < arraysize(kFileExtensions); ++i) { 218 for (const wchar_t* kExtension : kFileExtensions) {
219 base::string16 handle_name; 219 base::string16 handle_name;
220 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); 220 base::win::ScopedHandle marker(GetMarkerFile(kExtension));
221 CHECK(marker.IsValid()); 221 CHECK(marker.IsValid());
222 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name)); 222 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name));
223 CHECK_EQ(policy->AddKernelObjectToClose(L"File", handle_name.c_str()), 223 CHECK_EQ(policy->AddKernelObjectToClose(L"File", handle_name.c_str()),
224 SBOX_ALL_OK); 224 SBOX_ALL_OK);
225 command += (L" "); 225 command += (L" ");
226 command += handle_name; 226 command += handle_name;
227 } 227 }
228 228
229 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) << 229 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(command.c_str())) <<
230 "Failed: " << command; 230 "Failed: " << command;
231 } 231 }
232 232
233 TEST(HandleCloserTest, CheckStuffedHandle) { 233 TEST(HandleCloserTest, CheckStuffedHandle) {
234 TestRunner runner; 234 TestRunner runner;
235 runner.SetTimeout(2000); 235 runner.SetTimeout(2000);
236 runner.SetTestState(EVERY_STATE); 236 runner.SetTestState(EVERY_STATE);
237 sandbox::TargetPolicy* policy = runner.GetPolicy(); 237 sandbox::TargetPolicy* policy = runner.GetPolicy();
238 238
239 for (int i = 0; i < arraysize(kFileExtensions); ++i) { 239 for (const wchar_t* kExtension : kFileExtensions) {
240 base::string16 handle_name; 240 base::string16 handle_name;
241 base::win::ScopedHandle marker(GetMarkerFile(kFileExtensions[i])); 241 base::win::ScopedHandle marker(GetMarkerFile(kExtension));
242 CHECK(marker.IsValid()); 242 CHECK(marker.IsValid());
243 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name)); 243 CHECK(sandbox::GetHandleName(marker.Get(), &handle_name));
244 CHECK_EQ(policy->AddKernelObjectToClose(L"File", handle_name.c_str()), 244 CHECK_EQ(policy->AddKernelObjectToClose(L"File", handle_name.c_str()),
245 SBOX_ALL_OK); 245 SBOX_ALL_OK);
246 } 246 }
247 247
248 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckForEventHandles")); 248 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckForEventHandles"));
249 } 249 }
250 250
251 void WINAPI ThreadPoolTask(void* event, BOOLEAN timeout) { 251 void WINAPI ThreadPoolTask(void* event, BOOLEAN timeout) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 runner.SetTestState(AFTER_REVERT); 288 runner.SetTestState(AFTER_REVERT);
289 sandbox::TargetPolicy* policy = runner.GetPolicy(); 289 sandbox::TargetPolicy* policy = runner.GetPolicy();
290 290
291 // Sever the CSRSS connection by closing ALPC ports inside the sandbox. 291 // Sever the CSRSS connection by closing ALPC ports inside the sandbox.
292 CHECK_EQ(policy->AddKernelObjectToClose(L"ALPC Port", NULL), SBOX_ALL_OK); 292 CHECK_EQ(policy->AddKernelObjectToClose(L"ALPC Port", NULL), SBOX_ALL_OK);
293 293
294 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"RunThreadPool")); 294 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"RunThreadPool"));
295 } 295 }
296 296
297 } // namespace sandbox 297 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/crosscall_params.h ('k') | sandbox/win/src/interception_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698