OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/win/windows_version.h" | 5 #include "base/win/windows_version.h" |
6 #include "sandbox/win/src/handle_closer.h" | 6 #include "sandbox/win/src/handle_closer.h" |
7 #include "sandbox/win/src/sandbox.h" | 7 #include "sandbox/win/src/sandbox.h" |
8 #include "sandbox/win/src/sandbox_policy.h" | 8 #include "sandbox/win/src/sandbox_policy.h" |
9 #include "sandbox/win/src/sandbox_factory.h" | 9 #include "sandbox/win/src/sandbox_factory.h" |
10 #include "sandbox/win/tests/common/controller.h" | 10 #include "sandbox/win/tests/common/controller.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 // This tests that path canonicalization is actually disabled if we use \\?\ | 105 // This tests that path canonicalization is actually disabled if we use \\?\ |
106 // syntax. | 106 // syntax. |
107 TEST(NamedPipePolicyTest, CreatePipeCanonicalization) { | 107 TEST(NamedPipePolicyTest, CreatePipeCanonicalization) { |
108 // "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to | 108 // "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to |
109 // disable all string parsing and to send the string that follows it straight | 109 // disable all string parsing and to send the string that follows it straight |
110 // to the file system." | 110 // to the file system." |
111 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx | 111 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx |
112 wchar_t* argv[2] = { L"\\\\?\\pipe\\test\\..\\bleh", | 112 const wchar_t* argv[2] = { L"\\\\?\\pipe\\test\\..\\bleh", |
113 L"\\Device\\NamedPipe\\test" }; | 113 L"\\Device\\NamedPipe\\test" }; |
114 EXPECT_EQ(SBOX_TEST_SUCCEEDED, NamedPipe_Create(2, argv)); | 114 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
| 115 NamedPipe_Create(2, const_cast<wchar_t**>(argv))); |
115 } | 116 } |
116 | 117 |
117 // The same test as CreatePipe but this time using strict interceptions. | 118 // The same test as CreatePipe but this time using strict interceptions. |
118 TEST(NamedPipePolicyTest, CreatePipeStrictInterceptions) { | 119 TEST(NamedPipePolicyTest, CreatePipeStrictInterceptions) { |
119 TestRunner runner; | 120 TestRunner runner; |
120 runner.GetPolicy()->SetStrictInterceptions(); | 121 runner.GetPolicy()->SetStrictInterceptions(); |
121 | 122 |
122 // TODO(nsylvain): This policy is wrong because "*" is a valid char in a | 123 // TODO(nsylvain): This policy is wrong because "*" is a valid char in a |
123 // namedpipe name. Here we apply it like a wildcard. http://b/893603 | 124 // namedpipe name. Here we apply it like a wildcard. http://b/893603 |
124 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_NAMED_PIPES, | 125 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_NAMED_PIPES, |
125 TargetPolicy::NAMEDPIPES_ALLOW_ANY, | 126 TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
126 L"\\\\.\\pipe\\test*")); | 127 L"\\\\.\\pipe\\test*")); |
127 | 128 |
128 EXPECT_EQ(SBOX_TEST_SUCCEEDED, | 129 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
129 runner.RunTest(L"NamedPipe_Create \\\\.\\pipe\\testbleh")); | 130 runner.RunTest(L"NamedPipe_Create \\\\.\\pipe\\testbleh")); |
130 | 131 |
131 // On XP, the sandbox can create a pipe without any help but it fails on | 132 // On XP, the sandbox can create a pipe without any help but it fails on |
132 // Vista+, this is why we do not test the "denied" case. | 133 // Vista+, this is why we do not test the "denied" case. |
133 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA) { | 134 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA) { |
134 EXPECT_EQ(SBOX_TEST_DENIED, | 135 EXPECT_EQ(SBOX_TEST_DENIED, |
135 runner.RunTest(L"NamedPipe_Create \\\\.\\pipe\\bleh")); | 136 runner.RunTest(L"NamedPipe_Create \\\\.\\pipe\\bleh")); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 } // namespace sandbox | 140 } // namespace sandbox |
OLD | NEW |