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

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: 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
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",
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 ++size;
243 }
robertshield 2014/01/24 01:50:24 nit: no brackets needed for one line body. also sp
csharp 2014/01/24 16:22:59 Removed unneeded brackets. The function needs to
244
245 return size;
246 }
247
236 bool AddDllToBlacklist(const wchar_t* dll_name) { 248 bool AddDllToBlacklist(const wchar_t* dll_name) {
237 if (g_troublesome_dlls_cur_index >= kTroublesomeDllsMaxCount) 249 int blacklist_size = BlacklistSize();
250 // We need to leave one space at the end for the null pointer.
251 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount)
238 return false; 252 return false;
239 for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) { 253 for (int i=0; i < blacklist_size; ++i) {
240 if (!wcscmp(g_troublesome_dlls[i], dll_name)) 254 if (!_wcsicmp(g_troublesome_dlls[i], dll_name))
241 return true; 255 return true;
242 } 256 }
243 257
244 // Copy string to blacklist. 258 // Copy string to blacklist.
245 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1]; 259 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1];
246 wcscpy(str_buffer, dll_name); 260 wcscpy(str_buffer, dll_name);
247 261
248 g_troublesome_dlls[g_troublesome_dlls_cur_index] = str_buffer; 262 g_troublesome_dlls[blacklist_size] = str_buffer;
249 g_troublesome_dlls_cur_index++;
250 return true; 263 return true;
251 } 264 }
252 265
253 bool RemoveDllFromBlacklist(const wchar_t* dll_name) { 266 bool RemoveDllFromBlacklist(const wchar_t* dll_name) {
254 for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) { 267 int blacklist_size = BlacklistSize();
255 if (!wcscmp(g_troublesome_dlls[i], dll_name)) { 268 for (int i = 0; i < blacklist_size; ++i) {
269 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) {
256 // Found the thing to remove. Delete it then replace it with the last 270 // Found the thing to remove. Delete it then replace it with the last
257 // element. 271 // element.
258 g_troublesome_dlls_cur_index--;
259 delete[] g_troublesome_dlls[i]; 272 delete[] g_troublesome_dlls[i];
260 g_troublesome_dlls[i] = g_troublesome_dlls[g_troublesome_dlls_cur_index]; 273 g_troublesome_dlls[i] = g_troublesome_dlls[blacklist_size - 1];
261 g_troublesome_dlls[g_troublesome_dlls_cur_index] = NULL; 274 g_troublesome_dlls[blacklist_size - 1] = NULL;
262 return true; 275 return true;
263 } 276 }
264 } 277 }
265 return false; 278 return false;
266 } 279 }
267 280
268 bool Initialize(bool force) { 281 bool Initialize(bool force) {
269 #if defined(_WIN64) 282 #if defined(_WIN64)
270 // TODO(robertshield): Implement 64-bit support by providing 64-bit 283 // TODO(robertshield): Implement 64-bit support by providing 64-bit
271 // interceptors. 284 // 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. 354 // Mark the thunk storage as executable and prevent any future writes to it.
342 BOOL page_executable = VirtualProtect(&g_thunk_storage, 355 BOOL page_executable = VirtualProtect(&g_thunk_storage,
343 sizeof(g_thunk_storage), 356 sizeof(g_thunk_storage),
344 PAGE_EXECUTE_READ, 357 PAGE_EXECUTE_READ,
345 &old_protect); 358 &old_protect);
346 359
347 return NT_SUCCESS(ret) && page_executable; 360 return NT_SUCCESS(ret) && page_executable;
348 } 361 }
349 362
350 } // namespace blacklist 363 } // namespace blacklist
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698