hidapi: Avoid memcpy'ing to NULL.

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

Fixes #8428.
Reference PR #8431.

(cherry picked from commit c6d9fb1ad71462bc844c6ca41e2ac7fe7cec3883)
This commit is contained in:
Ryan C. Gordon 2023-11-06 13:48:07 -05:00
parent 9d7feaaf9e
commit 065d80716b
No known key found for this signature in database
GPG key ID: FA148B892AB48044

View file

@ -957,7 +957,9 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length)
size_t len = 0; size_t len = 0;
if (rpt != NULL) { if (rpt != NULL) {
len = (length < rpt->len)? length: rpt->len; len = (length < rpt->len)? length: rpt->len;
if (data != NULL) {
memcpy(data, rpt->data, len); 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);