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

Side by Side 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: Fix stripping. Created 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/memory_infra_background_whitelist.h"
6
7 #include <ctype.h>
8 #include <string.h>
9
10 #include <string>
11
12 namespace base {
13 namespace trace_event {
14 namespace {
15
16 // The names of dump providers whitelisted for background tracing. Dump
17 // providers can be added here only if the background mode dump has very
18 // less performance and memory overhead.
19 const char* const kDumpProviderWhitelist[] = {
20 // TODO(ssid): Fill this list with dump provider names which support
21 // background mode, crbug.com/613198.
22 nullptr // End of list marker.
23 };
24
25 // A list of string names that are allowed for the memory allocator dumps in
26 // background mode.
27 const char* const kAllocatorDumpNameWhitelist[] = {
28 // TODO(ssid): Fill this list with dump names, crbug.com/613198.
29 nullptr // End of list marker.
30 };
31
32 const char* const* g_dump_provider_whitelist = kDumpProviderWhitelist;
33 const char* const* g_allocator_dump_name_whitelist =
34 kAllocatorDumpNameWhitelist;
35
36 } // namespace
37
38 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) {
39 for (size_t i = 0; g_dump_provider_whitelist[i] != nullptr; ++i) {
40 if (strcmp(mdp_name, g_dump_provider_whitelist[i]) == 0)
41 return true;
42 }
43 return false;
44 }
45
46 bool IsMemoryAllocatorDumpNameWhitelisted(const std::string& name) {
47 // Remove special characters, numbers (including hexadecimal which are marked
48 // by '0x') from the given string.
49 const size_t length = name.size();
50 std::string stripped_str;
51 stripped_str.reserve(length);
52 bool parsing_hex = false;
53 for (size_t i = 0; i < length; ++i) {
54 if (parsing_hex) {
55 if (isxdigit(name[i])) {
56 continue;
57 } else {
58 parsing_hex = false;
59 }
60 }
61 if (i + 1 < length && name[i] == '0' && name[i + 1] == 'x') {
62 parsing_hex = true;
63 ++i;
64 } else if (isalpha(name[i]) ||
65 (name[i] == '/' && stripped_str.back() != '/')) {
66 // Do not add successive '/'(s) in |stripped_str|.
67 stripped_str.push_back(name[i]);
68 }
69 }
70
71 for (size_t i = 0; g_allocator_dump_name_whitelist[i] != nullptr; ++i) {
72 if (stripped_str == g_allocator_dump_name_whitelist[i]) {
73 return true;
74 }
75 }
76 return false;
77 }
78
79 void SetDumpProviderWhitelistForTesting(const char* const* list) {
80 g_dump_provider_whitelist = list;
81 }
82
83 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) {
84 g_allocator_dump_name_whitelist = list;
85 }
86
87 } // namespace trace_event
88 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_infra_background_whitelist.h ('k') | base/trace_event/process_memory_dump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698