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

Side by Side Diff: mojo/edk/system/broker_host_posix.cc

Issue 1983363002: [mojo-edk] Fix potential buffer overflow in BrokerHost (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 | « 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/broker_host.h" 5 #include "mojo/edk/system/broker_host.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 handles->at(1) = read_only_buffer->PassPlatformHandle().release(); 81 handles->at(1) = read_only_buffer->PassPlatformHandle().release();
82 message->SetHandles(std::move(handles)); 82 message->SetHandles(std::move(handles));
83 } 83 }
84 84
85 channel_->Write(std::move(message)); 85 channel_->Write(std::move(message));
86 } 86 }
87 87
88 void BrokerHost::OnChannelMessage(const void* payload, 88 void BrokerHost::OnChannelMessage(const void* payload,
89 size_t payload_size, 89 size_t payload_size,
90 ScopedPlatformHandleVectorPtr handles) { 90 ScopedPlatformHandleVectorPtr handles) {
91 if (payload_size < sizeof(BrokerMessageHeader))
92 return;
93
91 const BrokerMessageHeader* header = 94 const BrokerMessageHeader* header =
92 static_cast<const BrokerMessageHeader*>(payload); 95 static_cast<const BrokerMessageHeader*>(payload);
93 switch (header->type) { 96 switch (header->type) {
94 case BrokerMessageType::BUFFER_REQUEST: { 97 case BrokerMessageType::BUFFER_REQUEST:
95 const BufferRequestData* request = 98 if (payload_size ==
96 reinterpret_cast<const BufferRequestData*>(header + 1); 99 sizeof(BrokerMessageHeader) + sizeof(BufferRequestData)) {
97 OnBufferRequest(request->size); 100 const BufferRequestData* request =
101 reinterpret_cast<const BufferRequestData*>(header + 1);
102 OnBufferRequest(request->size);
103 return;
104 }
98 break; 105 break;
99 } 106
100 default: 107 default:
101 LOG(ERROR) << "Unexpected broker message type: " << header->type;
102 break; 108 break;
103 } 109 }
110
111 LOG(ERROR) << "Unexpected broker message type: " << header->type;
104 } 112 }
105 113
106 void BrokerHost::OnChannelError() { 114 void BrokerHost::OnChannelError() {
107 if (channel_) { 115 if (channel_) {
108 channel_->ShutDown(); 116 channel_->ShutDown();
109 channel_ = nullptr; 117 channel_ = nullptr;
110 } 118 }
111 119
112 delete this; 120 delete this;
113 } 121 }
114 122
115 void BrokerHost::WillDestroyCurrentMessageLoop() { 123 void BrokerHost::WillDestroyCurrentMessageLoop() {
116 delete this; 124 delete this;
117 } 125 }
118 126
119 } // namespace edk 127 } // namespace edk
120 } // namespace mojo 128 } // 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