mirror of
https://github.com/RPCS3/hidapi.git
synced 2026-07-01 18:25:51 -04:00
Add missing checks for malloc/calloc/CloseHandle (#702)
This commit is contained in:
@@ -1272,6 +1272,10 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
|
||||
return NULL;
|
||||
|
||||
dev = new_hid_device();
|
||||
if (!dev) {
|
||||
LOG("hid_open_path failed: Couldn't allocate memory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
libusb_get_device_list(usb_context, &devs);
|
||||
while ((usb_dev = devs[d++]) != NULL && !good_open) {
|
||||
@@ -1343,6 +1347,10 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_libusb_wrap_sys_device(intptr_t sys
|
||||
return NULL;
|
||||
|
||||
dev = new_hid_device();
|
||||
if (!dev) {
|
||||
LOG("libusb_wrap_sys_device failed: Couldn't allocate memory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = libusb_wrap_sys_device(usb_context, sys_dev, &dev->device_handle);
|
||||
if (res < 0) {
|
||||
|
||||
+28
-4
@@ -1045,7 +1045,10 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
|
||||
|
||||
end_of_function:
|
||||
free(interface_path);
|
||||
CloseHandle(device_handle);
|
||||
|
||||
if (device_handle != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(device_handle);
|
||||
}
|
||||
|
||||
if (pp_data) {
|
||||
HidD_FreePreparsedData(pp_data);
|
||||
@@ -1085,8 +1088,15 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
|
||||
/* The user passed the right number of bytes. Use the buffer as-is. */
|
||||
buf = (unsigned char *) data;
|
||||
} else {
|
||||
if (dev->write_buf == NULL)
|
||||
if (dev->write_buf == NULL) {
|
||||
dev->write_buf = (unsigned char *) malloc(dev->output_report_length);
|
||||
|
||||
if (dev->write_buf == NULL) {
|
||||
register_string_error(dev, L"hid_write/malloc");
|
||||
goto end_of_function;
|
||||
}
|
||||
}
|
||||
|
||||
buf = dev->write_buf;
|
||||
memcpy(buf, data, length);
|
||||
memset(buf + length, 0, dev->output_report_length - length);
|
||||
@@ -1253,8 +1263,15 @@ int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const u
|
||||
buf = (unsigned char *) data;
|
||||
length_to_send = length;
|
||||
} else {
|
||||
if (dev->feature_buf == NULL)
|
||||
if (dev->feature_buf == NULL) {
|
||||
dev->feature_buf = (unsigned char *) malloc(dev->feature_report_length);
|
||||
|
||||
if (dev->feature_buf == NULL) {
|
||||
register_string_error(dev, L"hid_send_feature_report/malloc");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
buf = dev->feature_buf;
|
||||
memcpy(buf, data, length);
|
||||
memset(buf + length, 0, dev->feature_report_length - length);
|
||||
@@ -1347,8 +1364,15 @@ int HID_API_EXPORT HID_API_CALL hid_send_output_report(hid_device* dev, const un
|
||||
buf = (unsigned char *) data;
|
||||
length_to_send = length;
|
||||
} else {
|
||||
if (dev->write_buf == NULL)
|
||||
if (dev->write_buf == NULL) {
|
||||
dev->write_buf = (unsigned char *) malloc(dev->output_report_length);
|
||||
|
||||
if (dev->write_buf == NULL) {
|
||||
register_string_error(dev, L"hid_send_output_report/malloc");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
buf = dev->write_buf;
|
||||
memcpy(buf, data, length);
|
||||
memset(buf + length, 0, dev->output_report_length - length);
|
||||
|
||||
Reference in New Issue
Block a user