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

Side by Side Diff: components/usb_service/usb_device_handle.cc

Issue 252153002: Fix chrome.usb control transfer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/usb_service/usb_device_handle.h" 5 #include "components/usb_service/usb_device_handle.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 scoped_refptr<net::IOBuffer> buffer = transfer.buffer; 227 scoped_refptr<net::IOBuffer> buffer = transfer.buffer;
228 switch (transfer.transfer_type) { 228 switch (transfer.transfer_type) {
229 case USB_TRANSFER_CONTROL: 229 case USB_TRANSFER_CONTROL:
230 // If the transfer is a control transfer we do not expose the control 230 // If the transfer is a control transfer we do not expose the control
231 // setup header to the caller. This logic strips off the header if 231 // setup header to the caller. This logic strips off the header if
232 // present before invoking the callback provided with the transfer. 232 // present before invoking the callback provided with the transfer.
233 if (actual_length > 0) { 233 if (actual_length > 0) {
234 CHECK(transfer.length >= LIBUSB_CONTROL_SETUP_SIZE) 234 CHECK(transfer.length >= LIBUSB_CONTROL_SETUP_SIZE)
235 << "buffer was not correctly set: too small for the control header"; 235 << "buffer was not correctly set: too small for the control header";
236 236
237 if (transfer.length >= actual_length && 237 if (transfer.length >= (LIBUSB_CONTROL_SETUP_SIZE + actual_length)) {
238 actual_length >= LIBUSB_CONTROL_SETUP_SIZE) {
239 // If the payload is zero bytes long, pad out the allocated buffer 238 // If the payload is zero bytes long, pad out the allocated buffer
240 // size to one byte so that an IOBuffer of that size can be allocated. 239 // size to one byte so that an IOBuffer of that size can be allocated.
241 scoped_refptr<net::IOBuffer> resized_buffer = 240 scoped_refptr<net::IOBuffer> resized_buffer =
242 new net::IOBuffer(static_cast<int>( 241 new net::IOBuffer(static_cast<int>(
243 std::max(actual_length, static_cast<size_t>(1)))); 242 std::max(actual_length, static_cast<size_t>(1))));
244 memcpy(resized_buffer->data(), 243 memcpy(resized_buffer->data(),
245 buffer->data() + LIBUSB_CONTROL_SETUP_SIZE, 244 buffer->data() + LIBUSB_CONTROL_SETUP_SIZE,
246 actual_length); 245 actual_length);
247 buffer = resized_buffer; 246 buffer = resized_buffer;
248 } 247 }
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 // Attempt-release all the interfaces. 648 // Attempt-release all the interfaces.
650 // It will be retained until the transfer cancellation is finished. 649 // It will be retained until the transfer cancellation is finished.
651 claimed_interfaces_.clear(); 650 claimed_interfaces_.clear();
652 651
653 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to 652 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to
654 // finish. 653 // finish.
655 device_ = NULL; 654 device_ = NULL;
656 } 655 }
657 656
658 } // namespace usb_service 657 } // namespace usb_service
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