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

Unified 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: Work when blacklist is length 0 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_elf/blacklist/blacklist.cc
diff --git a/chrome_elf/blacklist/blacklist.cc b/chrome_elf/blacklist/blacklist.cc
index eda611db41eba3a80f35c9f15964aaaa1c6bf47e..a90207e0457ca9356ba1e78aa55f464f5455dd78 100644
--- a/chrome_elf/blacklist/blacklist.cc
+++ b/chrome_elf/blacklist/blacklist.cc
@@ -19,8 +19,10 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
namespace blacklist{
-const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = {};
-int g_troublesome_dlls_cur_index = 0;
+const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = {
+ // Keep this null pointer here to mark the end of the list.
+ NULL,
+};
const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon";
const wchar_t kBeaconVersion[] = L"version";
@@ -233,11 +235,20 @@ bool ResetBeacon() {
return (result == ERROR_SUCCESS);
}
+int BlacklistSize() {
+ int size = -1;
+ while(blacklist::g_troublesome_dlls[++size] != NULL);
+
+ return size;
+}
+
bool AddDllToBlacklist(const wchar_t* dll_name) {
- if (g_troublesome_dlls_cur_index >= kTroublesomeDllsMaxCount)
+ int blacklist_size = BlacklistSize();
+ // We need to leave one space at the end for the null pointer.
+ if (blacklist_size + 1 >= kTroublesomeDllsMaxCount)
return false;
- for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) {
- if (!wcscmp(g_troublesome_dlls[i], dll_name))
+ for (int i=0; i < blacklist_size; ++i) {
+ if (!_wcsicmp(g_troublesome_dlls[i], dll_name))
return true;
}
@@ -245,20 +256,19 @@ bool AddDllToBlacklist(const wchar_t* dll_name) {
wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1];
wcscpy(str_buffer, dll_name);
- g_troublesome_dlls[g_troublesome_dlls_cur_index] = str_buffer;
- g_troublesome_dlls_cur_index++;
+ g_troublesome_dlls[blacklist_size] = str_buffer;
return true;
}
bool RemoveDllFromBlacklist(const wchar_t* dll_name) {
- for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) {
- if (!wcscmp(g_troublesome_dlls[i], dll_name)) {
+ int blacklist_size = BlacklistSize();
+ for (int i = 0; i < blacklist_size; ++i) {
+ if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) {
// Found the thing to remove. Delete it then replace it with the last
// element.
- g_troublesome_dlls_cur_index--;
delete[] g_troublesome_dlls[i];
- g_troublesome_dlls[i] = g_troublesome_dlls[g_troublesome_dlls_cur_index];
- g_troublesome_dlls[g_troublesome_dlls_cur_index] = NULL;
+ g_troublesome_dlls[i] = g_troublesome_dlls[blacklist_size - 1];
+ g_troublesome_dlls[blacklist_size - 1] = NULL;
return true;
}
}
« 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