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

Side by Side Diff: chrome/browser/usb/usb_device.cc

Issue 12096024: Add validation to length, packets and packetLength parameters (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/usb/usb_device.h" 5 #include "chrome/browser/usb/usb_device.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/synchronization/lock.h" 8 #include "base/synchronization/lock.h"
9 #include "chrome/browser/usb/usb_service.h" 9 #include "chrome/browser/usb/usb_service.h"
10 #include "third_party/libusb/src/libusb/libusb.h" 10 #include "third_party/libusb/src/libusb/libusb.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 SubmitTransfer(transfer, USB_TRANSFER_INTERRUPT, buffer, length, callback); 270 SubmitTransfer(transfer, USB_TRANSFER_INTERRUPT, buffer, length, callback);
271 } 271 }
272 272
273 void UsbDevice::IsochronousTransfer(const TransferDirection direction, 273 void UsbDevice::IsochronousTransfer(const TransferDirection direction,
274 const uint8 endpoint, net::IOBuffer* buffer, const size_t length, 274 const uint8 endpoint, net::IOBuffer* buffer, const size_t length,
275 const unsigned int packets, const unsigned int packet_length, 275 const unsigned int packets, const unsigned int packet_length,
276 const unsigned int timeout, const UsbTransferCallback& callback) { 276 const unsigned int timeout, const UsbTransferCallback& callback) {
277 CheckDevice(); 277 CheckDevice();
278 278
279 const uint64 total_length = packets * packet_length; 279 const uint64 total_length = packets * packet_length;
280 if (total_length > length) { 280 CHECK(packets <= length && total_length <= length) <<
281 callback.Run(USB_TRANSFER_LENGTH_SHORT, NULL, 0); 281 "transfer length is too small";
282 return;
283 }
284 282
285 struct libusb_transfer* const transfer = libusb_alloc_transfer(packets); 283 struct libusb_transfer* const transfer = libusb_alloc_transfer(packets);
286 const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint; 284 const uint8 new_endpoint = ConvertTransferDirection(direction) | endpoint;
287 libusb_fill_iso_transfer(transfer, handle_, new_endpoint, 285 libusb_fill_iso_transfer(transfer, handle_, new_endpoint,
288 reinterpret_cast<uint8*>(buffer->data()), length, packets, 286 reinterpret_cast<uint8*>(buffer->data()), length, packets,
289 HandleTransferCompletion, this, timeout); 287 HandleTransferCompletion, this, timeout);
290 libusb_set_iso_packet_lengths(transfer, packet_length); 288 libusb_set_iso_packet_lengths(transfer, packet_length);
291 289
292 SubmitTransfer(transfer, USB_TRANSFER_ISOCHRONOUS, buffer, length, callback); 290 SubmitTransfer(transfer, USB_TRANSFER_ISOCHRONOUS, buffer, length, callback);
293 } 291 }
(...skipping 12 matching lines...) Expand all
306 transfer.buffer = buffer; 304 transfer.buffer = buffer;
307 transfer.length = length; 305 transfer.length = length;
308 transfer.callback = callback; 306 transfer.callback = callback;
309 307
310 { 308 {
311 base::AutoLock lock(lock_); 309 base::AutoLock lock(lock_);
312 transfers_[handle] = transfer; 310 transfers_[handle] = transfer;
313 libusb_submit_transfer(handle); 311 libusb_submit_transfer(handle);
314 } 312 }
315 } 313 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/usb/usb_api.cc ('k') | chrome/test/data/extensions/api_test/usb/invalid_length_transfer/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698