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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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 #include "mojo/edk/system/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (data_num_bytes < sizeof(Header)) 130 if (data_num_bytes < sizeof(Header))
131 return nullptr; 131 return nullptr;
132 132
133 const Header* header = reinterpret_cast<const Header*>(data); 133 const Header* header = reinterpret_cast<const Header*>(data);
134 if (header->num_bytes != data_num_bytes) { 134 if (header->num_bytes != data_num_bytes) {
135 DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes 135 DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes
136 << " != " << data_num_bytes; 136 << " != " << data_num_bytes;
137 return nullptr; 137 return nullptr;
138 } 138 }
139 139
140 if (header->num_bytes < header->num_header_bytes) { 140 if (header->num_bytes < header->num_header_bytes ||
141 header->num_header_bytes < sizeof(Header)) {
Ken Rockot(use gerrit already) 2016/06/23 00:26:37 I made this condition explicit here, but we alread
Ken Rockot(use gerrit already) 2016/06/23 00:30:35 Wait, nevermind. I did backwards things in my head
Oliver Chang 2016/06/23 00:31:17 yep :) I missed this during the first review too
141 DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes << " < " 142 DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes << " < "
142 << header->num_header_bytes; 143 << header->num_header_bytes;
143 return nullptr; 144 return nullptr;
144 } 145 }
145 146
146 uint32_t extra_header_size = header->num_header_bytes - sizeof(Header); 147 uint32_t extra_header_size = header->num_header_bytes - sizeof(Header);
147 #if defined(OS_WIN) 148 #if defined(OS_WIN)
148 uint32_t max_handles = extra_header_size / sizeof(HandleEntry); 149 uint32_t max_handles = extra_header_size / sizeof(HandleEntry);
149 #elif defined(OS_MACOSX) && !defined(OS_IOS) 150 #elif defined(OS_MACOSX) && !defined(OS_IOS)
151 if (extra_header_size < sizeof(MachPortsExtraHeader)) {
152 DLOG(ERROR) << "Decoding invalid message: " << extra_header_size << " < "
153 << sizeof(MachPortsExtraHeader);
154 return nullptr;
155 }
150 uint32_t max_handles = (extra_header_size - sizeof(MachPortsExtraHeader)) / 156 uint32_t max_handles = (extra_header_size - sizeof(MachPortsExtraHeader)) /
Oliver Chang 2016/06/23 00:31:17 not sure if it's worth sanity checking max_handles
Ken Rockot(use gerrit already) 2016/06/23 00:42:51 oh right... done!
151 sizeof(MachPortsEntry); 157 sizeof(MachPortsEntry);
152 #endif 158 #endif
153 if (header->num_handles > max_handles) { 159 if (header->num_handles > max_handles) {
154 DLOG(ERROR) << "Decoding invalid message:" << header->num_handles 160 DLOG(ERROR) << "Decoding invalid message:" << header->num_handles
155 << " > " << max_handles; 161 << " > " << max_handles;
156 return nullptr; 162 return nullptr;
157 } 163 }
158 164
159 MessagePtr message(new Message(data_num_bytes - header->num_header_bytes, 165 MessagePtr message(new Message(data_num_bytes - header->num_header_bytes,
160 max_handles)); 166 max_handles));
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 574
569 bool Channel::OnControlMessage(Message::Header::MessageType message_type, 575 bool Channel::OnControlMessage(Message::Header::MessageType message_type,
570 const void* payload, 576 const void* payload,
571 size_t payload_size, 577 size_t payload_size,
572 ScopedPlatformHandleVectorPtr handles) { 578 ScopedPlatformHandleVectorPtr handles) {
573 return false; 579 return false;
574 } 580 }
575 581
576 } // namespace edk 582 } // namespace edk
577 } // namespace mojo 583 } // namespace mojo
OLDNEW
« 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