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

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

Issue 2001213002: [mojo-edk] Fix potential buffer overflow in BrokerHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 handles->at(0) = buffer->PassPlatformHandle().release(); 75 handles->at(0) = buffer->PassPlatformHandle().release();
76 message->SetHandles(std::move(handles)); 76 message->SetHandles(std::move(handles));
77 } 77 }
78 78
79 channel_->Write(std::move(message)); 79 channel_->Write(std::move(message));
80 } 80 }
81 81
82 void BrokerHost::OnChannelMessage(const void* payload, 82 void BrokerHost::OnChannelMessage(const void* payload,
83 size_t payload_size, 83 size_t payload_size,
84 ScopedPlatformHandleVectorPtr handles) { 84 ScopedPlatformHandleVectorPtr handles) {
85 if (payload_size < sizeof(BrokerMessageHeader))
86 return;
87
85 const BrokerMessageHeader* header = 88 const BrokerMessageHeader* header =
86 static_cast<const BrokerMessageHeader*>(payload); 89 static_cast<const BrokerMessageHeader*>(payload);
87 switch (header->type) { 90 switch (header->type) {
88 case BrokerMessageType::BUFFER_REQUEST: { 91 case BrokerMessageType::BUFFER_REQUEST:
89 const BufferRequestData* request = 92 if (payload_size ==
90 reinterpret_cast<const BufferRequestData*>(header + 1); 93 sizeof(BrokerMessageHeader) + sizeof(BufferRequestData)) {
91 OnBufferRequest(request->size); 94 const BufferRequestData* request =
95 reinterpret_cast<const BufferRequestData*>(header + 1);
96 OnBufferRequest(request->size);
97 return;
98 }
92 break; 99 break;
93 } 100
94 default: 101 default:
95 LOG(ERROR) << "Unexpected broker message type: " << header->type;
96 break; 102 break;
97 } 103 }
104
105 LOG(ERROR) << "Unexpected broker message type: " << header->type;
98 } 106 }
99 107
100 void BrokerHost::OnChannelError() { 108 void BrokerHost::OnChannelError() {
101 if (channel_) { 109 if (channel_) {
102 channel_->ShutDown(); 110 channel_->ShutDown();
103 channel_ = nullptr; 111 channel_ = nullptr;
104 } 112 }
105 113
106 delete this; 114 delete this;
107 } 115 }
108 116
109 void BrokerHost::WillDestroyCurrentMessageLoop() { 117 void BrokerHost::WillDestroyCurrentMessageLoop() {
110 delete this; 118 delete this;
111 } 119 }
112 120
113 } // namespace edk 121 } // namespace edk
114 } // namespace mojo 122 } // 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