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;
if (rpt != NULL) {
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;
free(rpt->data);
free(rpt);