diff options
author | reillyg <reillyg@chromium.org> | 2014-11-24 15:18:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-24 23:19:13 +0000 |
commit | 9f2714e9518a05c3e6c72737b1b0786b57164559 (patch) | |
tree | a33e7688fda18ba1c51447c8e2741c47d39e828e /device/hid | |
parent | 17ce82eae1ab15c8fb6da76d7dc10de6ff55c6bc (diff) | |
download | chromium_src-9f2714e9518a05c3e6c72737b1b0786b57164559.zip chromium_src-9f2714e9518a05c3e6c72737b1b0786b57164559.tar.gz chromium_src-9f2714e9518a05c3e6c72737b1b0786b57164559.tar.bz2 |
Check for failure to create an IOHIDDevice object.
IOHIDDeviceCreate can fail and return NULL instead of a reference to an
IOHIDDevice object. Handle this case by discarding the device or reporting
a failure to open it. This can happen if the IOKitUser library cannot get
a reference to the corresponding kernel object and is very rare.
BUG=434149
Review URL: https://codereview.chromium.org/739623003
Cr-Commit-Position: refs/heads/master@{#305516}
Diffstat (limited to 'device/hid')
-rw-r--r-- | device/hid/hid_service_mac.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/device/hid/hid_service_mac.cc b/device/hid/hid_service_mac.cc index 6e091a85..7d40cae 100644 --- a/device/hid/hid_service_mac.cc +++ b/device/hid/hid_service_mac.cc @@ -133,6 +133,11 @@ void PopulateDeviceInfo(io_service_t service, HidDeviceInfo* device_info) { base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( IOHIDDeviceCreate(kCFAllocatorDefault, service)); + if (!hid_device) { + VLOG(1) << "Unable to create IOHIDDevice object."; + return; + } + device_info->device_id = service_path; device_info->vendor_id = GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)); @@ -285,6 +290,12 @@ void HidServiceMac::Connect(const HidDeviceId& device_id, base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( IOHIDDeviceCreate(kCFAllocatorDefault, service)); + if (!hid_device) { + VLOG(1) << "Unable to create IOHIDDevice object."; + task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); + return; + } + IOReturn result = IOHIDDeviceOpen(hid_device, kIOHIDOptionsTypeNone); if (result != kIOReturnSuccess) { VLOG(1) << "Failed to open device: " |