| OLD | NEW |
| 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 "sandbox/win/tests/common/controller.h" | 5 #include "sandbox/win/tests/common/controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "base/process/process_handle.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 14 #include "sandbox/win/src/sandbox_factory.h" | 15 #include "sandbox/win/src/sandbox_factory.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 static const int kDefaultTimeout = 60000; | 19 static const int kDefaultTimeout = 60000; |
| 19 | 20 |
| 20 // Constructs a full path to a file inside the system32 folder. | 21 // Constructs a full path to a file inside the system32 folder. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 Sleep(INFINITE); | 298 Sleep(INFINITE); |
| 298 return SBOX_TEST_TIMED_OUT; | 299 return SBOX_TEST_TIMED_OUT; |
| 299 } | 300 } |
| 300 | 301 |
| 301 if (0 == _wcsicmp(argv[3], L"ping")) | 302 if (0 == _wcsicmp(argv[3], L"ping")) |
| 302 return SBOX_TEST_PING_OK; | 303 return SBOX_TEST_PING_OK; |
| 303 | 304 |
| 304 // If the caller shared a shared memory handle with us attempt to open it | 305 // If the caller shared a shared memory handle with us attempt to open it |
| 305 // in read only mode and sleep infinitely if we succeed. | 306 // in read only mode and sleep infinitely if we succeed. |
| 306 if (0 == _wcsicmp(argv[3], L"shared_memory_handle")) { | 307 if (0 == _wcsicmp(argv[3], L"shared_memory_handle")) { |
| 307 base::SharedMemoryHandle shared_handle = NULL; | 308 HANDLE raw_handle = nullptr; |
| 308 base::StringToUint( | 309 base::StringToUint(argv[4], reinterpret_cast<unsigned int*>(&raw_handle)); |
| 309 argv[4], reinterpret_cast<unsigned int*>(&shared_handle)); | 310 if (raw_handle == nullptr) |
| 310 if (shared_handle == NULL) | |
| 311 return SBOX_TEST_INVALID_PARAMETER; | 311 return SBOX_TEST_INVALID_PARAMETER; |
| 312 base::SharedMemoryHandle shared_handle(raw_handle, |
| 313 base::GetCurrentProcId()); |
| 312 base::SharedMemory read_only_view(shared_handle, true); | 314 base::SharedMemory read_only_view(shared_handle, true); |
| 313 if (!read_only_view.Map(0)) | 315 if (!read_only_view.Map(0)) |
| 314 return SBOX_TEST_INVALID_PARAMETER; | 316 return SBOX_TEST_INVALID_PARAMETER; |
| 315 std::string contents(reinterpret_cast<char*>(read_only_view.memory())); | 317 std::string contents(reinterpret_cast<char*>(read_only_view.memory())); |
| 316 if (contents != "Hello World") | 318 if (contents != "Hello World") |
| 317 return SBOX_TEST_INVALID_PARAMETER; | 319 return SBOX_TEST_INVALID_PARAMETER; |
| 318 Sleep(INFINITE); | 320 Sleep(INFINITE); |
| 319 return SBOX_TEST_TIMED_OUT; | 321 return SBOX_TEST_TIMED_OUT; |
| 320 } | 322 } |
| 321 | 323 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 361 |
| 360 target->LowerToken(); | 362 target->LowerToken(); |
| 361 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) { | 363 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) { |
| 362 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; | 364 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; |
| 363 } | 365 } |
| 364 | 366 |
| 365 return command(argc - 4, argv + 4); | 367 return command(argc - 4, argv + 4); |
| 366 } | 368 } |
| 367 | 369 |
| 368 } // namespace sandbox | 370 } // namespace sandbox |
| OLD | NEW |