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

Unified Diff: device/hid/hid_connection_win.cc

Issue 2804313005: Make HidConnection::Read reentrancy safe (Closed)
Patch Set: Rebased. Created 3 years, 8 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 | « device/hid/hid_connection_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection_win.cc
diff --git a/device/hid/hid_connection_win.cc b/device/hid/hid_connection_win.cc
index fb65d846675762f935ea911b31605f299251a2d6..ad4ca2a26f8c153fbf3c55756dd2f7c9426e2198 100644
--- a/device/hid/hid_connection_win.cc
+++ b/device/hid/hid_connection_win.cc
@@ -179,13 +179,26 @@ void HidConnectionWin::OnReadComplete(scoped_refptr<net::IOBuffer> buffer,
std::unique_ptr<PendingHidTransfer> transfer = UnlinkTransfer(transfer_raw);
DWORD bytes_transferred;
- if (signaled && GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
- &bytes_transferred, FALSE)) {
- CompleteRead(buffer, bytes_transferred, callback);
- } else {
+ if (!signaled || !GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
+ &bytes_transferred, FALSE)) {
HID_PLOG(EVENT) << "HID read failed";
callback.Run(false, nullptr, 0);
+ return;
+ }
+
+ if (bytes_transferred < 1) {
+ HID_LOG(EVENT) << "HID read too short.";
+ callback.Run(false, nullptr, 0);
+ return;
+ }
+
+ uint8_t report_id = buffer->data()[0];
+ if (IsReportIdProtected(report_id)) {
+ PlatformRead(callback);
+ return;
}
+
+ callback.Run(true, buffer, bytes_transferred);
}
void HidConnectionWin::OnReadFeatureComplete(
« no previous file with comments | « device/hid/hid_connection_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698