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

Unified Diff: device/usb/webusb_descriptors.cc

Issue 1999083003: UBSAN: Fix left-shifts of negative values in webusb_descriptors.cc. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/webusb_descriptors.cc
diff --git a/device/usb/webusb_descriptors.cc b/device/usb/webusb_descriptors.cc
index 44a51b893179852733fad4e8f802e070e32d20ab..c21dc6f39c29e4c2cc1617854fa322a9776d9b3c 100644
--- a/device/usb/webusb_descriptors.cc
+++ b/device/usb/webusb_descriptors.cc
@@ -294,7 +294,8 @@ void OnReadWebUsbAllowedOriginsHeader(
return;
}
- uint16_t new_length = buffer->data()[2] | (buffer->data()[3] << 8);
+ const uint8_t* data = reinterpret_cast<uint8_t*>(buffer->data());
+ uint16_t new_length = data[2] | (data[3] << 8);
scoped_refptr<IOBufferWithSize> new_buffer = new IOBufferWithSize(new_length);
device_handle->ControlTransfer(
USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, UsbDeviceHandle::DEVICE,
@@ -351,7 +352,8 @@ void OnReadBosDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
return;
}
- uint16_t new_length = buffer->data()[2] | (buffer->data()[3] << 8);
+ const uint8_t* data = reinterpret_cast<uint8_t*>(buffer->data());
+ uint16_t new_length = data[2] | (data[3] << 8);
scoped_refptr<IOBufferWithSize> new_buffer = new IOBufferWithSize(new_length);
device_handle->ControlTransfer(
USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, UsbDeviceHandle::DEVICE,
« 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