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

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

Issue 138903022: Cleanup browser blacklist code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Responding to comments Created 6 years, 11 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
« no previous file with comments | « chrome_elf/blacklist/blacklist.h ('k') | chrome_elf/blacklist/blacklist_interceptions.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 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 "chrome_elf/blacklist/blacklist.h" 5 #include "chrome_elf/blacklist/blacklist.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "chrome_elf/blacklist/blacklist_interceptions.h" 10 #include "chrome_elf/blacklist/blacklist_interceptions.h"
11 #include "sandbox/win/src/interception_internal.h" 11 #include "sandbox/win/src/interception_internal.h"
12 #include "sandbox/win/src/internal_types.h" 12 #include "sandbox/win/src/internal_types.h"
13 #include "sandbox/win/src/sandbox_utils.h" 13 #include "sandbox/win/src/sandbox_utils.h"
14 #include "sandbox/win/src/service_resolver.h" 14 #include "sandbox/win/src/service_resolver.h"
15 #include "version.h" // NOLINT 15 #include "version.h" // NOLINT
16 16
17 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx 17 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
18 extern "C" IMAGE_DOS_HEADER __ImageBase; 18 extern "C" IMAGE_DOS_HEADER __ImageBase;
19 19
20 namespace blacklist{ 20 namespace blacklist{
21 21
22 const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = {}; 22 const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = {
23 int g_troublesome_dlls_cur_index = 0; 23 L"libsvn_tsvn32.dll",
robertshield 2014/01/24 16:38:35 Do you want to move just the above line to a separ
csharp 2014/01/24 16:42:08 Done.
24 // Keep this null pointer here to mark the end of the list.
25 NULL,
26 };
24 27
25 const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon"; 28 const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon";
26 const wchar_t kBeaconVersion[] = L"version"; 29 const wchar_t kBeaconVersion[] = L"version";
27 const wchar_t kBeaconState[] = L"state"; 30 const wchar_t kBeaconState[] = L"state";
28 31
29 } // namespace blacklist 32 } // namespace blacklist
30 33
31 // Allocate storage for thunks in a page of this module to save on doing 34 // Allocate storage for thunks in a page of this module to save on doing
32 // an extra allocation at run time. 35 // an extra allocation at run time.
33 #pragma section(".crthunk",read,execute) 36 #pragma section(".crthunk",read,execute)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 kBeaconState, 229 kBeaconState,
227 0, 230 0,
228 REG_DWORD, 231 REG_DWORD,
229 reinterpret_cast<LPBYTE>(&blacklist_state), 232 reinterpret_cast<LPBYTE>(&blacklist_state),
230 sizeof(blacklist_state)); 233 sizeof(blacklist_state));
231 ::RegCloseKey(key); 234 ::RegCloseKey(key);
232 235
233 return (result == ERROR_SUCCESS); 236 return (result == ERROR_SUCCESS);
234 } 237 }
235 238
239 int BlacklistSize() {
240 int size = 0;
241 while(blacklist::g_troublesome_dlls[++size] != NULL);
242
243 return size;
244 }
245
236 bool AddDllToBlacklist(const wchar_t* dll_name) { 246 bool AddDllToBlacklist(const wchar_t* dll_name) {
237 if (g_troublesome_dlls_cur_index >= kTroublesomeDllsMaxCount) 247 int blacklist_size = BlacklistSize();
248 // We need to leave one space at the end for the null pointer.
249 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount)
238 return false; 250 return false;
239 for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) { 251 for (int i=0; i < blacklist_size; ++i) {
240 if (!wcscmp(g_troublesome_dlls[i], dll_name)) 252 if (!_wcsicmp(g_troublesome_dlls[i], dll_name))
241 return true; 253 return true;
242 } 254 }
243 255
244 // Copy string to blacklist. 256 // Copy string to blacklist.
245 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1]; 257 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1];
246 wcscpy(str_buffer, dll_name); 258 wcscpy(str_buffer, dll_name);
247 259
248 g_troublesome_dlls[g_troublesome_dlls_cur_index] = str_buffer; 260 g_troublesome_dlls[blacklist_size] = str_buffer;
249 g_troublesome_dlls_cur_index++;
250 return true; 261 return true;
251 } 262 }
252 263
253 bool RemoveDllFromBlacklist(const wchar_t* dll_name) { 264 bool RemoveDllFromBlacklist(const wchar_t* dll_name) {
254 for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) { 265 int blacklist_size = BlacklistSize();
255 if (!wcscmp(g_troublesome_dlls[i], dll_name)) { 266 for (int i = 0; i < blacklist_size; ++i) {
267 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) {
256 // Found the thing to remove. Delete it then replace it with the last 268 // Found the thing to remove. Delete it then replace it with the last
257 // element. 269 // element.
258 g_troublesome_dlls_cur_index--;
259 delete[] g_troublesome_dlls[i]; 270 delete[] g_troublesome_dlls[i];
260 g_troublesome_dlls[i] = g_troublesome_dlls[g_troublesome_dlls_cur_index]; 271 g_troublesome_dlls[i] = g_troublesome_dlls[blacklist_size - 1];
261 g_troublesome_dlls[g_troublesome_dlls_cur_index] = NULL; 272 g_troublesome_dlls[blacklist_size - 1] = NULL;
262 return true; 273 return true;
263 } 274 }
264 } 275 }
265 return false; 276 return false;
266 } 277 }
267 278
268 bool Initialize(bool force) { 279 bool Initialize(bool force) {
269 #if defined(_WIN64) 280 #if defined(_WIN64)
270 // TODO(robertshield): Implement 64-bit support by providing 64-bit 281 // TODO(robertshield): Implement 64-bit support by providing 64-bit
271 // interceptors. 282 // interceptors.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Mark the thunk storage as executable and prevent any future writes to it. 352 // Mark the thunk storage as executable and prevent any future writes to it.
342 BOOL page_executable = VirtualProtect(&g_thunk_storage, 353 BOOL page_executable = VirtualProtect(&g_thunk_storage,
343 sizeof(g_thunk_storage), 354 sizeof(g_thunk_storage),
344 PAGE_EXECUTE_READ, 355 PAGE_EXECUTE_READ,
345 &old_protect); 356 &old_protect);
346 357
347 return NT_SUCCESS(ret) && page_executable; 358 return NT_SUCCESS(ret) && page_executable;
348 } 359 }
349 360
350 } // namespace blacklist 361 } // namespace blacklist
OLDNEW
« no previous file with comments | « chrome_elf/blacklist/blacklist.h ('k') | chrome_elf/blacklist/blacklist_interceptions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698