| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <limits.h> | 5 #include <limits.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 |
| 8 #include <iostream> | 9 #include <iostream> |
| 10 #include <iterator> |
| 9 #include <string> | 11 #include <string> |
| 12 #include <utility> |
| 10 #include <vector> | 13 #include <vector> |
| 11 | 14 |
| 12 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 13 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 14 #include "third_party/re2/src/re2/re2.h" | 17 #include "third_party/re2/src/re2/re2.h" |
| 15 #include "tools/ipc_fuzzer/message_lib/message_file.h" | 18 #include "tools/ipc_fuzzer/message_lib/message_file.h" |
| 16 #include "tools/ipc_fuzzer/message_lib/message_names.h" | 19 #include "tools/ipc_fuzzer/message_lib/message_names.h" |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 123 } |
| 121 | 124 |
| 122 ipc_fuzzer::MessageVector input_message_vector; | 125 ipc_fuzzer::MessageVector input_message_vector; |
| 123 for (const base::FilePath::StringType& name : base::SplitString( | 126 for (const base::FilePath::StringType& name : base::SplitString( |
| 124 args[0], base::FilePath::StringType(1, ','), | 127 args[0], base::FilePath::StringType(1, ','), |
| 125 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 128 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 126 ipc_fuzzer::MessageVector message_vector; | 129 ipc_fuzzer::MessageVector message_vector; |
| 127 if (!ipc_fuzzer::MessageFile::Read(base::FilePath(name), &message_vector)) | 130 if (!ipc_fuzzer::MessageFile::Read(base::FilePath(name), &message_vector)) |
| 128 return EXIT_FAILURE; | 131 return EXIT_FAILURE; |
| 129 input_message_vector.insert(input_message_vector.end(), | 132 input_message_vector.insert(input_message_vector.end(), |
| 130 message_vector.begin(), message_vector.end()); | 133 std::make_move_iterator(message_vector.begin()), |
| 131 message_vector.weak_clear(); | 134 std::make_move_iterator(message_vector.end())); |
| 132 } | 135 } |
| 133 | 136 |
| 134 bool has_indices = cmd->HasSwitch(kInSwitch); | 137 bool has_indices = cmd->HasSwitch(kInSwitch); |
| 135 std::vector<bool> indices; | 138 std::vector<bool> indices; |
| 136 | 139 |
| 137 if (has_indices) { | 140 if (has_indices) { |
| 138 indices.resize(input_message_vector.size(), false); | 141 indices.resize(input_message_vector.size(), false); |
| 139 for (const std::string& cur : base::SplitString( | 142 for (const std::string& cur : base::SplitString( |
| 140 cmd->GetSwitchValueASCII(kInSwitch), ",", base::TRIM_WHITESPACE, | 143 cmd->GetSwitchValueASCII(kInSwitch), ",", base::TRIM_WHITESPACE, |
| 141 base::SPLIT_WANT_ALL)) { | 144 base::SPLIT_WANT_ALL)) { |
| 142 int index = atoi(cur.c_str()); | 145 int index = atoi(cur.c_str()); |
| 143 if (index >= 0 && static_cast<size_t>(index) < indices.size()) | 146 if (index >= 0 && static_cast<size_t>(index) < indices.size()) |
| 144 indices[index] = true; | 147 indices[index] = true; |
| 145 } | 148 } |
| 146 } | 149 } |
| 147 | 150 |
| 148 ipc_fuzzer::MessageVector output_message_vector; | 151 ipc_fuzzer::MessageVector output_message_vector; |
| 149 std::vector<size_t> remap_vector; | 152 std::vector<size_t> remap_vector; |
| 150 | 153 |
| 151 for (size_t i = 0; i < input_message_vector.size(); ++i) { | 154 for (size_t i = 0; i < input_message_vector.size(); ++i) { |
| 152 bool valid = (i >= start_index && i < end_index); | 155 bool valid = (i >= start_index && i < end_index); |
| 153 if (valid && has_regexp) { | 156 if (valid && has_regexp) { |
| 154 valid = MessageMatches(input_message_vector[i], filter_pattern); | 157 valid = MessageMatches(input_message_vector[i].get(), filter_pattern); |
| 155 } | 158 } |
| 156 if (valid && has_indices) { | 159 if (valid && has_indices) { |
| 157 valid = indices[i]; | 160 valid = indices[i]; |
| 158 } | 161 } |
| 159 if (valid != invert) { | 162 if (valid != invert) { |
| 160 output_message_vector.push_back(input_message_vector[i]); | 163 output_message_vector.push_back(std::move(input_message_vector[i])); |
| 161 remap_vector.push_back(i); | 164 remap_vector.push_back(i); |
| 162 input_message_vector[i] = NULL; | |
| 163 } | 165 } |
| 164 } | 166 } |
| 165 | 167 |
| 166 if (perform_dump) { | 168 if (perform_dump) { |
| 167 for (size_t i = 0; i < output_message_vector.size(); ++i) { | 169 for (size_t i = 0; i < output_message_vector.size(); ++i) { |
| 168 std::cout << remap_vector[i] << ". " | 170 std::cout << remap_vector[i] << ". " |
| 169 << MessageName(output_message_vector[i]) << "\n"; | 171 << MessageName(output_message_vector[i].get()) << "\n"; |
| 170 } | 172 } |
| 171 } else { | 173 } else { |
| 172 if (!ipc_fuzzer::MessageFile::Write( | 174 if (!ipc_fuzzer::MessageFile::Write( |
| 173 base::FilePath(output_file_name), output_message_vector)) { | 175 base::FilePath(output_file_name), output_message_vector)) { |
| 174 return EXIT_FAILURE; | 176 return EXIT_FAILURE; |
| 175 } | 177 } |
| 176 } | 178 } |
| 177 | 179 |
| 178 return EXIT_SUCCESS; | 180 return EXIT_SUCCESS; |
| 179 } | 181 } |
| OLD | NEW |