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

Unified Diff: device/hid/hid_connection_linux.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.cc ('k') | device/hid/hid_connection_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection_linux.cc
diff --git a/device/hid/hid_connection_linux.cc b/device/hid/hid_connection_linux.cc
index ec348ed6abc4cc5a429f74bd65c012c0ba0b096e..62d06c35d6a7610d9227ac6b918774e2658b9105 100644
--- a/device/hid/hid_connection_linux.cc
+++ b/device/hid/hid_connection_linux.cc
@@ -242,6 +242,12 @@ void HidConnectionLinux::PlatformSendFeatureReport(
void HidConnectionLinux::ProcessInputReport(scoped_refptr<net::IOBuffer> buffer,
size_t size) {
DCHECK(thread_checker().CalledOnValidThread());
+ DCHECK_GE(size, 1u);
+
+ uint8_t report_id = buffer->data()[0];
+ if (IsReportIdProtected(report_id))
+ return;
+
PendingHidReport report;
report.buffer = buffer;
report.size = size;
@@ -251,13 +257,17 @@ void HidConnectionLinux::ProcessInputReport(scoped_refptr<net::IOBuffer> buffer,
void HidConnectionLinux::ProcessReadQueue() {
DCHECK(thread_checker().CalledOnValidThread());
+
+ // Hold a reference to |this| to prevent a callback from freeing this object
+ // during the loop.
+ scoped_refptr<HidConnectionLinux> self(this);
while (pending_reads_.size() && pending_reports_.size()) {
PendingHidRead read = pending_reads_.front();
PendingHidReport report = pending_reports_.front();
+ pending_reads_.pop();
pending_reports_.pop();
- if (CompleteRead(report.buffer, report.size, read.callback))
- pending_reads_.pop();
+ read.callback.Run(true, report.buffer, report.size);
}
}
« no previous file with comments | « device/hid/hid_connection.cc ('k') | device/hid/hid_connection_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698