File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -425,14 +425,17 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
425
425
/* Fill out the record */
426
426
cur_dev -> next = NULL ;
427
427
str = device_interface_detail_data -> DevicePath ;
428
+ cur_dev -> path = NULL ;
428
429
if (str ) {
430
+ #pragma GCC diagnostic push
431
+ #pragma GCC diagnostic ignored "-Wstringop-overflow"
429
432
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
433
438
}
434
- else
435
- cur_dev -> path = NULL ;
436
439
437
440
/* Serial Number */
438
441
res = HidD_GetSerialNumberString (write_handle , wstr , sizeof (wstr ));
You can’t perform that action at this time.
0 commit comments