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

Side by Side Diff: device/hid/hid_connection_mac.cc

Issue 2528243002: Fix silent truncations when extracting values from CheckedNumeric (Closed)
Patch Set: compile fix Created 4 years 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
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "device/hid/hid_connection_mac.h" 5 #include "device/hid/hid_connection_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/numerics/safe_math.h" 10 #include "base/numerics/safe_math.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 CFIndex report_length) { 129 CFIndex report_length) {
130 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context); 130 HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
131 if (result != kIOReturnSuccess) { 131 if (result != kIOReturnSuccess) {
132 HID_LOG(EVENT) << "Failed to read input report: " << HexErrorCode(result); 132 HID_LOG(EVENT) << "Failed to read input report: " << HexErrorCode(result);
133 return; 133 return;
134 } 134 }
135 135
136 scoped_refptr<net::IOBufferWithSize> buffer; 136 scoped_refptr<net::IOBufferWithSize> buffer;
137 if (connection->device_info()->has_report_id()) { 137 if (connection->device_info()->has_report_id()) {
138 // report_id is already contained in report_bytes 138 // report_id is already contained in report_bytes
139 buffer = new net::IOBufferWithSize( 139 buffer =
140 base::CheckedNumeric<size_t>(report_length).ValueOrDie()); 140 new net::IOBufferWithSize(base::checked_cast<size_t>(report_length));
141 memcpy(buffer->data(), report_bytes, report_length); 141 memcpy(buffer->data(), report_bytes, report_length);
142 } else { 142 } else {
143 buffer = new net::IOBufferWithSize( 143 buffer = new net::IOBufferWithSize(static_cast<size_t>(
144 (base::CheckedNumeric<size_t>(report_length) + 1).ValueOrDie()); 144 (base::CheckedNumeric<size_t>(report_length) + 1).ValueOrDie()));
145 buffer->data()[0] = 0; 145 buffer->data()[0] = 0;
146 memcpy(buffer->data() + 1, report_bytes, report_length); 146 memcpy(buffer->data() + 1, report_bytes, report_length);
147 } 147 }
148 148
149 connection->ProcessInputReport(buffer); 149 connection->ProcessInputReport(buffer);
150 } 150 }
151 151
152 void HidConnectionMac::ProcessInputReport( 152 void HidConnectionMac::ProcessInputReport(
153 scoped_refptr<net::IOBufferWithSize> buffer) { 153 scoped_refptr<net::IOBufferWithSize> buffer) {
154 DCHECK(thread_checker().CalledOnValidThread()); 154 DCHECK(thread_checker().CalledOnValidThread());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 this, 237 this,
238 base::Bind(callback, false))); 238 base::Bind(callback, false)));
239 } 239 }
240 } 240 }
241 241
242 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) { 242 void HidConnectionMac::ReturnAsyncResult(const base::Closure& callback) {
243 callback.Run(); 243 callback.Run();
244 } 244 }
245 245
246 } // namespace device 246 } // namespace device
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_media_stream_track_host_base.cc ('k') | gpu/command_buffer/client/gles2_implementation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698