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

Side by Side Diff: mojo/edk/system/ports/message.h

Issue 1987593002: [mojo-edk] Sanity checks on ports message parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « mojo/edk/system/node_controller.cc ('k') | mojo/edk/system/ports/message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #ifndef MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ 5 #ifndef MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_
6 #define MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ 6 #define MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "mojo/edk/system/ports/name.h" 12 #include "mojo/edk/system/ports/name.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace edk { 15 namespace edk {
16 namespace ports { 16 namespace ports {
17 17
18 // A message consists of a header (array of bytes), payload (array of bytes) 18 // A message consists of a header (array of bytes), payload (array of bytes)
19 // and an array of ports. The header is used by the Node implementation. 19 // and an array of ports. The header is used by the Node implementation.
20 // 20 //
21 // This class is designed to be subclassed, and the subclass is responsible for 21 // This class is designed to be subclassed, and the subclass is responsible for
22 // providing the underlying storage. The header size will be aligned, and it 22 // providing the underlying storage. The header size will be aligned, and it
23 // should be followed in memory by the array of ports and finally the payload. 23 // should be followed in memory by the array of ports and finally the payload.
24 // 24 //
25 // NOTE: This class does not manage the lifetime of the ports it references. 25 // NOTE: This class does not manage the lifetime of the ports it references.
26 class Message { 26 class Message {
27 public: 27 public:
28 virtual ~Message() {} 28 virtual ~Message() {}
29 29
30 // Inspect the message at |bytes| and return the size of each section. 30 // Inspect the message at |bytes| and return the size of each section. Returns
31 static void Parse(const void* bytes, 31 // |false| if the message is malformed and |true| otherwise.
32 static bool Parse(const void* bytes,
32 size_t num_bytes, 33 size_t num_bytes,
33 size_t* num_header_bytes, 34 size_t* num_header_bytes,
34 size_t* num_payload_bytes, 35 size_t* num_payload_bytes,
35 size_t* num_ports_bytes); 36 size_t* num_ports_bytes);
36 37
37 void* mutable_header_bytes() { return start_; } 38 void* mutable_header_bytes() { return start_; }
38 const void* header_bytes() const { return start_; } 39 const void* header_bytes() const { return start_; }
39 size_t num_header_bytes() const { return num_header_bytes_; } 40 size_t num_header_bytes() const { return num_header_bytes_; }
40 41
41 void* mutable_payload_bytes() { 42 void* mutable_payload_bytes() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 size_t num_payload_bytes_ = 0; 84 size_t num_payload_bytes_ = 0;
84 }; 85 };
85 86
86 using ScopedMessage = std::unique_ptr<Message>; 87 using ScopedMessage = std::unique_ptr<Message>;
87 88
88 } // namespace ports 89 } // namespace ports
89 } // namespace edk 90 } // namespace edk
90 } // namespace mojo 91 } // namespace mojo
91 92
92 #endif // MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_ 93 #endif // MOJO_EDK_SYSTEM_PORTS_MESSAGE_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/node_controller.cc ('k') | mojo/edk/system/ports/message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698