Skip to content
This repository was archived by the owner on Feb 26, 2020. It is now read-only.

Commit e89ea56

Browse files
author
Alexandre Colucci
committed
I have seen several crashes on macOS 10.12.6 caused by the fact that IOHIDManagerCopyDevices() returned NULL. Calling CFSetGetCount() on a NULL CFSetRef causes a crash. The fix consists of checking if the CFSetRef is not NULL before using it. Here is a backtrace of a crash:
0x00007fffd04a5118 CFSetGetCount + 24 0x000000010c15147f hid_enumerate (hid.c:427) 0x000000010c151acc hid_open (hid.c:529)
1 parent a6a622f commit e89ea56

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mac/hid.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
407407
/* Get a list of the Devices */
408408
IOHIDManagerSetDeviceMatching(hid_mgr, NULL);
409409
CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
410+
if (device_set == NULL)
411+
return NULL;
410412

411413
/* Convert the list into a C array so we can iterate easily. */
412414
num_devices = CFSetGetCount(device_set);
@@ -1081,6 +1083,8 @@ int main(void)
10811083
IOHIDManagerOpen(mgr, kIOHIDOptionsTypeNone);
10821084

10831085
CFSetRef device_set = IOHIDManagerCopyDevices(mgr);
1086+
if (device_set == NULL)
1087+
return 0;
10841088

10851089
CFIndex num_devices = CFSetGetCount(device_set);
10861090
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));

0 commit comments

Comments
 (0)