hidapi: Avoid memcpy'ing to NULL.

(This fix was originally from @themightyoarfish on GitHub. Thanks!)

Fixes #8428.
Reference PR #8431.
This commit is contained in:
Ryan C. Gordon 2023-11-06 13:48:07 -05:00
parent 4d1aecc225
commit c6d9fb1ad7
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 3 additions and 1 deletions

View File

@ -1230,7 +1230,9 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length)
return buffer (data), and delete the liked list item. */ return buffer (data), and delete the liked list item. */
struct input_report *rpt = dev->input_reports; struct input_report *rpt = dev->input_reports;
size_t len = (length < rpt->len)? length: rpt->len; size_t len = (length < rpt->len)? length: rpt->len;
memcpy(data, rpt->data, len); if (data != NULL) {
memcpy(data, rpt->data, len);
}
dev->input_reports = rpt->next; dev->input_reports = rpt->next;
free(rpt->data); free(rpt->data);
free(rpt); free(rpt);