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

Unified Diff: mojo/edk/system/channel.cc

Issue 1975073002: [mojo-edk] Broadcast surprise port disruptions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reenable-clean-shutdown
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/edk/system/node_channel.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/channel.cc
diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc
index 79928845a4453b0648359677e486e8f7b56abc39..56509b5b609f44886a6b883ffaba121fb3d0daa9 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -121,12 +121,6 @@ Channel::Message::~Message() {
// static
Channel::MessagePtr Channel::Message::Deserialize(const void* data,
size_t data_num_bytes) {
-#if !defined(OS_WIN) && !(defined(OS_MACOSX) && !defined(OS_IOS))
- // We only serialize messages into other messages when performing message
- // relay on Windows and OSX.
- NOTREACHED();
- return nullptr;
-#else
if (data_num_bytes < sizeof(Header))
return nullptr;
@@ -137,6 +131,10 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
return nullptr;
}
+#if defined(MOJO_EDK_LEGACY_PROTOCOL)
+ size_t payload_size = data_num_bytes - sizeof(Header);
+ const char* payload = static_cast<const char*>(data) + sizeof(Header);
+#else
if (header->num_bytes < header->num_header_bytes ||
header->num_header_bytes < sizeof(Header)) {
DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes << " < "
@@ -145,6 +143,11 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
}
uint32_t extra_header_size = header->num_header_bytes - sizeof(Header);
+ size_t payload_size = data_num_bytes - header->num_header_bytes;
+ const char* payload =
+ static_cast<const char*>(data) + header->num_header_bytes;
+#endif // defined(MOJO_EDK_LEGACY_PROTOCOL)
+
#if defined(OS_WIN)
uint32_t max_handles = extra_header_size / sizeof(HandleEntry);
#elif defined(OS_MACOSX) && !defined(OS_IOS)
@@ -155,32 +158,34 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
}
uint32_t max_handles = (extra_header_size - sizeof(MachPortsExtraHeader)) /
sizeof(MachPortsEntry);
-#endif
+#else
+ const uint32_t max_handles = 0;
+#endif // defined(OS_WIN)
+
if (header->num_handles > max_handles || max_handles > kMaxAttachedHandles) {
DLOG(ERROR) << "Decoding invalid message:" << header->num_handles
<< " > " << max_handles;
return nullptr;
}
- MessagePtr message(new Message(data_num_bytes - header->num_header_bytes,
- max_handles));
+ MessagePtr message(new Message(payload_size, max_handles));
DCHECK_EQ(message->data_num_bytes(), data_num_bytes);
+
+ // Copy all payload bytes.
+ if (payload_size)
+ memcpy(message->mutable_payload(), payload, payload_size);
+
+#if !defined(MOJO_EDK_LEGACY_PROTOCOL)
DCHECK_EQ(message->extra_header_size(), extra_header_size);
DCHECK_EQ(message->header_->num_header_bytes, header->num_header_bytes);
- if (data_num_bytes > header->num_header_bytes) {
- // Copy all payload bytes.
- memcpy(message->mutable_payload(),
- static_cast<const char*>(data) + header->num_header_bytes,
- data_num_bytes - header->num_header_bytes);
- }
-
if (message->extra_header_size()) {
// Copy extra header bytes.
memcpy(message->mutable_extra_header(),
static_cast<const char*>(data) + sizeof(Header),
message->extra_header_size());
}
+#endif
message->header_->num_handles = header->num_handles;
#if defined(OS_WIN)
@@ -194,7 +199,6 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
#endif
return message;
-#endif
}
size_t Channel::Message::payload_size() const {
« no previous file with comments | « no previous file | mojo/edk/system/node_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698