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

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: Fixes. 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
15 namespace {
16 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
17 const char* const* g_allocator_dump_name_whitelist_for_tetsting = nullptr;
18 }
19
20 bool IsMemoryDumpProviderWhitelisted(const char* mdp_name) {
21 const char* const* whitelist = g_dump_provider_whitelist_for_testing
22 ? g_dump_provider_whitelist_for_testing
23 : kDumpProviderWhitelist;
24 for (size_t i = 0; whitelist[i] != nullptr; ++i) {
25 if (strcmp(mdp_name, whitelist[i]) == 0)
26 return true;
27 }
28 return false;
29 }
30
31 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.
32 // Remove special characters, numbers (including hexadecimal which are marked
33 // by '0x') from the given string.
34 const size_t length = mad_name.size();
35 std::string stripped_str;
36 stripped_str.reserve(length);
37 bool parsing_hex = false;
38 for (size_t i = 0; i < length; ++i) {
39 if (parsing_hex) {
40 if (isxdigit(mad_name[i])) {
41 continue;
42 } else {
43 parsing_hex = false;
44 }
45 }
46 if (i + 1 < length && mad_name[i] == '0' && mad_name[i + 1] == 'x') {
47 parsing_hex = true;
48 ++i;
49 } else if (isalpha(mad_name[i])) {
50 stripped_str.push_back(mad_name[i]);
51 }
52 }
53
54 const char* const* whitelist =
55 g_allocator_dump_name_whitelist_for_tetsting
56 ? g_allocator_dump_name_whitelist_for_tetsting
57 : kAllocatorDumpNameWhitelist;
58 for (size_t i = 0; whitelist[i] != nullptr; ++i) {
59 if (stripped_str == whitelist[i]) {
60 return true;
61 }
62 }
63 return false;
64 }
65
66 void SetDumpProviderWhitelistForTesting(const char* const* list) {
67 g_dump_provider_whitelist_for_testing = list;
68 }
69
70 void SetAllocatorDumpNameWhitelistForTesting(const char* const* list) {
71 g_allocator_dump_name_whitelist_for_tetsting = list;
72 }
73
74 } // namespace trace_event
75 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698