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

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

Issue 2095493003: [mojo-edk] Fix unchecked header sizes channel messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 | no next file » | 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 ac97fbbf29c68463d9f9d3cde643b10241f13599..79928845a4453b0648359677e486e8f7b56abc39 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -137,7 +137,8 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
return nullptr;
}
- if (header->num_bytes < header->num_header_bytes) {
+ if (header->num_bytes < header->num_header_bytes ||
+ header->num_header_bytes < sizeof(Header)) {
DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes << " < "
<< header->num_header_bytes;
return nullptr;
@@ -147,10 +148,15 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
#if defined(OS_WIN)
uint32_t max_handles = extra_header_size / sizeof(HandleEntry);
#elif defined(OS_MACOSX) && !defined(OS_IOS)
+ if (extra_header_size < sizeof(MachPortsExtraHeader)) {
+ DLOG(ERROR) << "Decoding invalid message: " << extra_header_size << " < "
+ << sizeof(MachPortsExtraHeader);
+ return nullptr;
+ }
uint32_t max_handles = (extra_header_size - sizeof(MachPortsExtraHeader)) /
sizeof(MachPortsEntry);
#endif
- if (header->num_handles > max_handles) {
+ if (header->num_handles > max_handles || max_handles > kMaxAttachedHandles) {
DLOG(ERROR) << "Decoding invalid message:" << header->num_handles
<< " > " << max_handles;
return nullptr;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698