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

Side by Side Diff: chrome_elf/blacklist/test/blacklist_test.cc

Issue 300933002: Finch Blacklist is now added to the Hardcoded blacklist. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Making Rob's changes Created 6 years, 6 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/environment.h" 5 #include "base/environment.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_native_library.h" 10 #include "base/scoped_native_library.h"
(...skipping 14 matching lines...) Expand all
25 25
26 const wchar_t kDll2Beacon[] = L"{F70A0100-2889-4629-9B44-610FE5C73231}"; 26 const wchar_t kDll2Beacon[] = L"{F70A0100-2889-4629-9B44-610FE5C73231}";
27 const wchar_t kDll3Beacon[] = L"{9E056AEC-169E-400c-B2D0-5A07E3ACE2EB}"; 27 const wchar_t kDll3Beacon[] = L"{9E056AEC-169E-400c-B2D0-5A07E3ACE2EB}";
28 28
29 extern const wchar_t* kEnvVars[]; 29 extern const wchar_t* kEnvVars[];
30 30
31 extern "C" { 31 extern "C" {
32 // When modifying the blacklist in the test process, use the exported test dll 32 // When modifying the blacklist in the test process, use the exported test dll
33 // functions on the test blacklist dll, not the ones linked into the test 33 // functions on the test blacklist dll, not the ones linked into the test
34 // executable itself. 34 // executable itself.
35 __declspec(dllimport) bool TestDll_AddDllsFromRegistryToBlacklist();
35 __declspec(dllimport) bool TestDll_AddDllToBlacklist(const wchar_t* dll_name); 36 __declspec(dllimport) bool TestDll_AddDllToBlacklist(const wchar_t* dll_name);
36 __declspec(dllimport) bool TestDll_IsBlacklistInitialized(); 37 __declspec(dllimport) bool TestDll_IsBlacklistInitialized();
37 __declspec(dllimport) bool TestDll_RemoveDllFromBlacklist( 38 __declspec(dllimport) bool TestDll_RemoveDllFromBlacklist(
38 const wchar_t* dll_name); 39 const wchar_t* dll_name);
39 __declspec(dllimport) bool TestDll_SuccessfullyBlocked( 40 __declspec(dllimport) bool TestDll_SuccessfullyBlocked(
40 const wchar_t** blocked_dlls, 41 const wchar_t** blocked_dlls,
41 int* size); 42 int* size);
42 } 43 }
43 44
44 class BlacklistTest : public testing::Test { 45 class BlacklistTest : public testing::Test {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls); 155 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
155 EXPECT_EQ(0, num_blocked_dlls); 156 EXPECT_EQ(0, num_blocked_dlls);
156 157
157 struct TestData { 158 struct TestData {
158 const wchar_t* dll_name; 159 const wchar_t* dll_name;
159 const wchar_t* dll_beacon; 160 const wchar_t* dll_beacon;
160 } test_data[] = { 161 } test_data[] = {
161 { kTestDllName2, kDll2Beacon }, 162 { kTestDllName2, kDll2Beacon },
162 { kTestDllName3, kDll3Beacon } 163 { kTestDllName3, kDll3Beacon }
163 }; 164 };
164 for (int i = 0 ; i < arraysize(test_data); ++i) { 165 for (int i = 0; i < arraysize(test_data); ++i) {
165 // Add the DLL to the blacklist, ensure that it is not loaded both by 166 // Add the DLL to the blacklist, ensure that it is not loaded both by
166 // inspecting the handle returned by LoadLibrary and by looking for an 167 // inspecting the handle returned by LoadLibrary and by looking for an
167 // environment variable that is set when the DLL's entry point is called. 168 // environment variable that is set when the DLL's entry point is called.
168 EXPECT_TRUE(TestDll_AddDllToBlacklist(test_data[i].dll_name)); 169 EXPECT_TRUE(TestDll_AddDllToBlacklist(test_data[i].dll_name));
169 base::ScopedNativeLibrary dll_blacklisted( 170 base::ScopedNativeLibrary dll_blacklisted(
170 current_dir.Append(test_data[i].dll_name)); 171 current_dir.Append(test_data[i].dll_name));
171 EXPECT_FALSE(dll_blacklisted.is_valid()); 172 EXPECT_FALSE(dll_blacklisted.is_valid());
172 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); 173 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
173 dll_blacklisted.Reset(NULL); 174 dll_blacklisted.Reset(NULL);
174 175
(...skipping 25 matching lines...) Expand all
200 dll_blacklisted_different_case.Reset(NULL); 201 dll_blacklisted_different_case.Reset(NULL);
201 202
202 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str())); 203 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(uppercase_name.c_str()));
203 204
204 // The blocked dll was removed, so we shouldn't get anything returned 205 // The blocked dll was removed, so we shouldn't get anything returned
205 // here. 206 // here.
206 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls); 207 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
207 EXPECT_EQ(0, num_blocked_dlls); 208 EXPECT_EQ(0, num_blocked_dlls);
208 } 209 }
209 } 210 }
211
212 TEST_F(BlacklistTest, AddDllsFromRegistryToBlacklist) {
213 base::FilePath current_dir;
214 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));
215
216 // Ensure that the blacklist is loaded.
217 ASSERT_TRUE(TestDll_IsBlacklistInitialized());
218
219 base::win::RegKey finch_blacklist_registry_key(
220 HKEY_CURRENT_USER,
221 blacklist::kRegistryFinchListPath,
222 KEY_QUERY_VALUE | KEY_SET_VALUE);
223
224 int num_dlls = finch_blacklist_registry_key.GetValueCount();
225
226 // Collect any dll names currently stored in the regisry and delete them.
227 std::vector<std::wstring> dlls(num_dlls);
228 for (int i = 0; i < num_dlls; ++i) {
229 std::wstring name;
230 finch_blacklist_registry_key.GetValueNameAt(i, &name);
231
232 std::wstring value;
233 finch_blacklist_registry_key.ReadValue(name.c_str(), &value);
234
235 dlls[i] = value;
robertshield 2014/06/03 03:03:00 prefer dlls.push_back(value);
krstnmnlsn 2014/06/03 19:30:16 Done.
236 }
237
238 for (int i = 0; i < num_dlls; ++i) {
239 finch_blacklist_registry_key.DeleteValue(dlls[i].c_str());
240 }
241
242 struct TestData {
243 const wchar_t* dll_name;
244 const wchar_t* dll_beacon;
245 } test_data[] = {{kTestDllName2, kDll2Beacon}, {kTestDllName3, kDll3Beacon}};
246
247 // Add the test dlls to the registry (with their name as both key and value).
248 for (int i = 0; i < arraysize(test_data); ++i) {
249 finch_blacklist_registry_key.WriteValue(test_data[i].dll_name,
250 test_data[i].dll_name);
251 }
252
253 EXPECT_TRUE(TestDll_AddDllsFromRegistryToBlacklist());
254
255 for (int i = 0; i < arraysize(test_data); ++i) {
256 // Ensure that the dll has not been loaded both by
257 // inspecting the handle returned by LoadLibrary and by looking for an
258 // environment variable that is set when the DLL's entry point is called.
259 base::ScopedNativeLibrary dll_blacklisted(
260 current_dir.Append(test_data[i].dll_name));
261 EXPECT_FALSE(dll_blacklisted.is_valid());
262 EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
263 dll_blacklisted.Reset(NULL);
264
265 // Ensure that the dll is recorded as blocked.
266 int array_size = 1;
267 const wchar_t* blocked_dll = NULL;
268 TestDll_SuccessfullyBlocked(&blocked_dll, &array_size);
269 EXPECT_EQ(1, array_size);
270 EXPECT_EQ(test_data[i].dll_name, base::string16(blocked_dll));
271
272 // Remove the DLL from the blacklist. Ensure that it loads and that its
273 // entry point was called.
274 EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(test_data[i].dll_name));
275 base::ScopedNativeLibrary dll(current_dir.Append(test_data[i].dll_name));
276 EXPECT_TRUE(dll.is_valid());
277 EXPECT_NE(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0));
278 dll.Reset(NULL);
279
280 ::SetEnvironmentVariable(test_data[i].dll_beacon, NULL);
281
282 // The blocked dll was removed, so we shouldn't get anything returned
283 // here.
284 int num_blocked_dlls = 0;
285 TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
286 EXPECT_EQ(0, num_blocked_dlls);
287 }
288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698