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

Side by Side Diff: tools/ipc_fuzzer/message_lib/message_file_reader.cc

Issue 2972773004: Remove ScopedVector from tools/ipc_fuzzer/. (Closed)
Patch Set: rev Created 3 years, 5 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
14 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
15 #include "tools/ipc_fuzzer/message_lib/message_cracker.h" 16 #include "tools/ipc_fuzzer/message_lib/message_cracker.h"
16 #include "tools/ipc_fuzzer/message_lib/message_file.h" 17 #include "tools/ipc_fuzzer/message_lib/message_file.h"
17 #include "tools/ipc_fuzzer/message_lib/message_file_format.h" 18 #include "tools/ipc_fuzzer/message_lib/message_file_format.h"
18 #include "tools/ipc_fuzzer/message_lib/message_names.h" 19 #include "tools/ipc_fuzzer/message_lib/message_names.h"
19 20
20 namespace ipc_fuzzer { 21 namespace ipc_fuzzer {
21 22
22 namespace { 23 namespace {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 121
121 CHECK_EQ(info.message_end, info.pickle_end); 122 CHECK_EQ(info.message_end, info.pickle_end);
122 size_t msglen = info.message_end - begin; 123 size_t msglen = info.message_end - begin;
123 if (msglen > INT_MAX) { 124 if (msglen > INT_MAX) {
124 LOG(ERROR) << "Message too large."; 125 LOG(ERROR) << "Message too large.";
125 return false; 126 return false;
126 } 127 }
127 128
128 // Copy is necessary to fix message type later. 129 // Copy is necessary to fix message type later.
129 IPC::Message const_message(begin, msglen); 130 IPC::Message const_message(begin, msglen);
130 IPC::Message* message = new IPC::Message(const_message); 131 messages_->push_back(base::MakeUnique<IPC::Message>(const_message));
131 messages_->push_back(message);
132 file_data_.remove_prefix(msglen); 132 file_data_.remove_prefix(msglen);
133 } 133 }
134 return true; 134 return true;
135 } 135 }
136 136
137 bool Reader::ReadStringTable() { 137 bool Reader::ReadStringTable() {
138 size_t name_count = header_->name_count; 138 size_t name_count = header_->name_count;
139 if (!name_count) 139 if (!name_count)
140 return true; 140 return true;
141 if (name_count > file_data_.size() / sizeof(NameTableEntry)) { 141 if (name_count > file_data_.size() / sizeof(NameTableEntry)) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 188 }
189 } 189 }
190 return true; 190 return true;
191 } 191 }
192 192
193 // Message types are based on line numbers, so a minor edit of *_messages.h 193 // Message types are based on line numbers, so a minor edit of *_messages.h
194 // changes the types of messages in that file. The types are fixed here to 194 // changes the types of messages in that file. The types are fixed here to
195 // increase the lifetime of message files. This is only a partial fix because 195 // increase the lifetime of message files. This is only a partial fix because
196 // message arguments and structure layouts can change as well. 196 // message arguments and structure layouts can change as well.
197 void Reader::FixMessageTypes() { 197 void Reader::FixMessageTypes() {
198 for (MessageVector::iterator it = messages_->begin(); 198 for (const auto& message : *messages_) {
199 it != messages_->end(); ++it) { 199 uint32_t type = message->type();
200 uint32_t type = (*it)->type();
201 const std::string& name = name_map_.TypeToName(type); 200 const std::string& name = name_map_.TypeToName(type);
202 uint32_t correct_type = MessageNames::GetInstance()->NameToType(name); 201 uint32_t correct_type = MessageNames::GetInstance()->NameToType(name);
203 if (type != correct_type) 202 if (type != correct_type)
204 MessageCracker::SetMessageType(*it, correct_type); 203 MessageCracker::SetMessageType(message.get(), correct_type);
205 } 204 }
206 } 205 }
207 206
208 bool Reader::Read(MessageVector* messages) { 207 bool Reader::Read(MessageVector* messages) {
209 messages_ = messages; 208 messages_ = messages;
210 209
211 if (!MapFile()) 210 if (!MapFile())
212 return false; 211 return false;
213 if (!ReadHeader()) 212 if (!ReadHeader())
214 return false; 213 return false;
(...skipping 11 matching lines...) Expand all
226 } 225 }
227 226
228 } // namespace 227 } // namespace
229 228
230 bool MessageFile::Read(const base::FilePath& path, MessageVector* messages) { 229 bool MessageFile::Read(const base::FilePath& path, MessageVector* messages) {
231 Reader reader(path); 230 Reader reader(path);
232 return reader.Read(messages); 231 return reader.Read(messages);
233 } 232 }
234 233
235 } // namespace ipc_fuzzer 234 } // namespace ipc_fuzzer
OLDNEW
« no previous file with comments | « tools/ipc_fuzzer/message_lib/message_file.h ('k') | tools/ipc_fuzzer/message_lib/message_file_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698