| 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 <stdlib.h> | 6 #include <stdlib.h> | 
| 7 #include <iostream> | 7 #include <iostream> | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 101     if (temp > 0) | 101     if (temp > 0) | 
| 102       end_index = static_cast<size_t>(temp); | 102       end_index = static_cast<size_t>(temp); | 
| 103   } | 103   } | 
| 104 | 104 | 
| 105   bool has_regexp = cmd->HasSwitch(kRegexpSwitch); | 105   bool has_regexp = cmd->HasSwitch(kRegexpSwitch); | 
| 106   RE2 filter_pattern(cmd->GetSwitchValueASCII(kRegexpSwitch)); | 106   RE2 filter_pattern(cmd->GetSwitchValueASCII(kRegexpSwitch)); | 
| 107 | 107 | 
| 108   bool invert = cmd->HasSwitch(kInvertSwitch); | 108   bool invert = cmd->HasSwitch(kInvertSwitch); | 
| 109   bool perform_dump = cmd->HasSwitch(kDumpSwitch); | 109   bool perform_dump = cmd->HasSwitch(kDumpSwitch); | 
| 110 | 110 | 
| 111   std::vector<base::FilePath::StringType> input_file_names; |  | 
| 112   base::FilePath::StringType output_file_name; | 111   base::FilePath::StringType output_file_name; | 
| 113   base::SplitString(args[0], ',', &input_file_names); |  | 
| 114 | 112 | 
| 115   if (!perform_dump) { | 113   if (!perform_dump) { | 
| 116     if (args.size() < 2) { | 114     if (args.size() < 2) { | 
| 117       usage(); | 115       usage(); | 
| 118       return EXIT_FAILURE; | 116       return EXIT_FAILURE; | 
| 119     } | 117     } | 
| 120     output_file_name = args[1]; | 118     output_file_name = args[1]; | 
| 121   } | 119   } | 
| 122 | 120 | 
| 123   ipc_fuzzer::MessageVector input_message_vector; | 121   ipc_fuzzer::MessageVector input_message_vector; | 
| 124   for (std::vector<base::FilePath::StringType>::iterator | 122   for (const base::FilePath::StringType& name : base::SplitString( | 
| 125       it = input_file_names.begin(); it != input_file_names.end(); ++it) { | 123            args[0], base::FilePath::StringType(1, ','), | 
|  | 124            base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 
| 126     ipc_fuzzer::MessageVector message_vector; | 125     ipc_fuzzer::MessageVector message_vector; | 
| 127     if (!ipc_fuzzer::MessageFile::Read(base::FilePath(*it), &message_vector)) | 126     if (!ipc_fuzzer::MessageFile::Read(base::FilePath(name), &message_vector)) | 
| 128       return EXIT_FAILURE; | 127       return EXIT_FAILURE; | 
| 129     input_message_vector.insert(input_message_vector.end(), | 128     input_message_vector.insert(input_message_vector.end(), | 
| 130                                 message_vector.begin(), message_vector.end()); | 129                                 message_vector.begin(), message_vector.end()); | 
| 131     message_vector.weak_clear(); | 130     message_vector.weak_clear(); | 
| 132   } | 131   } | 
| 133 | 132 | 
| 134   bool has_indices = cmd->HasSwitch(kInSwitch); | 133   bool has_indices = cmd->HasSwitch(kInSwitch); | 
| 135   std::vector<bool> indices; | 134   std::vector<bool> indices; | 
| 136 | 135 | 
| 137   if (has_indices) { | 136   if (has_indices) { | 
| 138     indices.resize(input_message_vector.size(), false); | 137     indices.resize(input_message_vector.size(), false); | 
| 139     std::vector<std::string> index_strings; | 138     for (const std::string& cur : base::SplitString( | 
| 140     base::SplitString(cmd->GetSwitchValueASCII(kInSwitch), ',', &index_strings); | 139              cmd->GetSwitchValueASCII(kInSwitch), ",", base::TRIM_WHITESPACE, | 
| 141     for (std::vector<std::string>::iterator it = index_strings.begin(); | 140              base::SPLIT_WANT_ALL)) { | 
| 142          it != index_strings.end(); ++it) { | 141       int index = atoi(cur.c_str()); | 
| 143       int index = atoi(it->c_str()); |  | 
| 144       if (index >= 0 && static_cast<size_t>(index) < indices.size()) | 142       if (index >= 0 && static_cast<size_t>(index) < indices.size()) | 
| 145         indices[index] = true; | 143         indices[index] = true; | 
| 146     } | 144     } | 
| 147   } | 145   } | 
| 148 | 146 | 
| 149   ipc_fuzzer::MessageVector output_message_vector; | 147   ipc_fuzzer::MessageVector output_message_vector; | 
| 150   std::vector<size_t> remap_vector; | 148   std::vector<size_t> remap_vector; | 
| 151 | 149 | 
| 152   for (size_t i = 0; i < input_message_vector.size(); ++i) { | 150   for (size_t i = 0; i < input_message_vector.size(); ++i) { | 
| 153     bool valid = (i >= start_index && i < end_index); | 151     bool valid = (i >= start_index && i < end_index); | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 171     } | 169     } | 
| 172   } else { | 170   } else { | 
| 173     if (!ipc_fuzzer::MessageFile::Write( | 171     if (!ipc_fuzzer::MessageFile::Write( | 
| 174             base::FilePath(output_file_name), output_message_vector)) { | 172             base::FilePath(output_file_name), output_message_vector)) { | 
| 175       return EXIT_FAILURE; | 173       return EXIT_FAILURE; | 
| 176     } | 174     } | 
| 177   } | 175   } | 
| 178 | 176 | 
| 179   return EXIT_SUCCESS; | 177   return EXIT_SUCCESS; | 
| 180 } | 178 } | 
| OLD | NEW | 
|---|