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

Unified Diff: base/trace_event/memory_infra_background_whitelist.cc

Issue 2006943003: [tracing] Sanitize process memory dumps for background mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@whitelist_mdp
Patch Set: Fixes. Created 4 years, 7 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
Index: base/trace_event/memory_infra_background_whitelist.cc
diff --git a/base/trace_event/memory_infra_background_whitelist.cc b/base/trace_event/memory_infra_background_whitelist.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e60234b583c1f584e89d03956d4d26af531f7a5
--- /dev/null
+++ b/base/trace_event/memory_infra_background_whitelist.cc
@@ -0,0 +1,75 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/trace_event/memory_infra_background_whitelist.h"
+
+#include <ctype.h>
+#include <string.h>
+
+#include <string>
+
+namespace base {
+namespace trace_event {
+
+namespace {
+const char* const* g_dump_provider_whitelist_for_testing = nullptr;
Primiano Tucci (use gerrit) 2016/06/02 20:24:04 Probably a bit more maintainable if you: - Just ca
ssid 2016/06/03 01:59:46 Thanks, done
+const char* const* g_allocator_dump_name_whitelist_for_tetsting = nullptr;
+}
+
+bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) {
+ const char* const* whitelist = g_dump_provider_whitelist_for_testing
+ ? g_dump_provider_whitelist_for_testing
+ : kDumpProviderWhitelist;
+ for (size_t i = 0; whitelist[i] != nullptr; ++i) {
+ if (strcmp(mdp_name, whitelist[i]) == 0)
+ return true;
+ }
+ return false;
+}
+
+bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& mad_name) {
Primiano Tucci (use gerrit) 2016/06/02 20:24:04 just |name| should be fine here. It's quite funny
ssid 2016/06/03 01:59:46 haha done.
+ // Remove special characters, numbers (including hexadecimal which are marked
+ // by '0x') from the given string.
+ const size_t length = mad_name.size();
+ std::string stripped_str;
+ stripped_str.reserve(length);
+ bool parsing_hex = false;
+ for (size_t i = 0; i < length; ++i) {
+ if (parsing_hex) {
+ if (isxdigit(mad_name[i])) {
+ continue;
+ } else {
+ parsing_hex = false;
+ }
+ }
+ if (i + 1 < length && mad_name[i] == '0' && mad_name[i + 1] == 'x') {
+ parsing_hex = true;
+ ++i;
+ } else if (isalpha(mad_name[i])) {
+ stripped_str.push_back(mad_name[i]);
+ }
+ }
+
+ const char* const* whitelist =
+ g_allocator_dump_name_whitelist_for_tetsting
+ ? g_allocator_dump_name_whitelist_for_tetsting
+ : kAllocatorDumpNameWhitelist;
+ for (size_t i = 0; whitelist[i] != nullptr; ++i) {
+ if (stripped_str == whitelist[i]) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void SetDumpProviderWhitelistForTesting(const char* const* list) {
+ g_dump_provider_whitelist_for_testing = list;
+}
+
+void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) {
+ g_allocator_dump_name_whitelist_for_tetsting = list;
+}
+
+} // namespace trace_event
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698