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

Commit 743b75d

Browse files
authored
Merge pull request #1 from paritytech/SafetyCheckCFSetGetCount
Safety check to prevent crash on macOS when IOHIDManagerCopyDevices() returns NULL
2 parents a6a622f + e89ea56 commit 743b75d

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)