Skip to content

Commit 302fd40

Browse files
committed
Fix warning
1 parent 2684efe commit 302fd40

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

hidapi/windows/hid.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,17 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
425425
/* Fill out the record */
426426
cur_dev->next = NULL;
427427
str = device_interface_detail_data->DevicePath;
428+
cur_dev->path = NULL;
428429
if (str) {
430+
#pragma GCC diagnostic push
431+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
429432
len = strlen(str);
430-
cur_dev->path = (char*) calloc(len+1, sizeof(char));
431-
strncpy(cur_dev->path, str, len+1);
432-
cur_dev->path[len] = '\0';
433+
len = min(len, 4096); // Do not accept device paths over 4096 bytes to avoid possible overflows
434+
cur_dev->path = (char*) calloc(len+1, sizeof(char));
435+
strncpy(cur_dev->path, str, len+1);
436+
cur_dev->path[len] = '\0';
437+
#pragma GCC diagnostic pop
433438
}
434-
else
435-
cur_dev->path = NULL;
436439

437440
/* Serial Number */
438441
res = HidD_GetSerialNumberString(write_handle, wstr, sizeof(wstr));

0 commit comments

Comments
 (0)