Page MenuHomeFreeBSD

libusb: implement libusb_get_platform_descriptor
ClosedPublic

Authored by aokblast on Jul 11 2025, 4:01 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Oct 14, 5:22 AM
Unknown Object (File)
Sun, Oct 12, 9:44 PM
Unknown Object (File)
Sun, Oct 12, 9:44 PM
Unknown Object (File)
Sun, Oct 12, 9:44 PM
Unknown Object (File)
Sun, Oct 12, 9:44 PM
Unknown Object (File)
Sun, Oct 12, 9:44 PM
Unknown Object (File)
Sun, Oct 12, 9:44 PM
Unknown Object (File)
Sun, Oct 12, 10:15 AM

Details

Summary

This function is added from libusb 1.0.27 which is used to
parse platform descriptor.

Sponsored By: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

adrian added inline comments.
lib/libusb/libusb10_desc.c
730

are there any scenarios where there'll be uninit'ed data from malloc() that you aren't overwriting with the relevant capability info?
(Normally I use calloc()) for stuff like this so it's zero-init'ed and I don't need to worry about leaking info.

lib/libusb/libusb10_desc.c
730

No. The size malloced will be fill by memcpy later. However, it is harmless to use calloc so we can switch to it.

lwhsu added inline comments.
lib/libusb/libusb10_desc.c
723

Will this be an issue that we dereference bos_cap before checking if it's NULL in if (bos_cap == NULL ?

lib/libusb/libusb10_desc.c
735

Do we need to free() desc since it's allocated by calloc() above? Or maybe move this part before calling calloc() ?

emaste added inline comments.
lib/libusb/libusb10_desc.c
723

Indeed, this is the sort of issue Coverity will complain about as well. Either bos_cap can be NULL and we need to check here before dereferencing, or it cannot be NULL and the check below is unnecessary.

It looks like lgpl libusb just assumes it is not NULL.

Other than the moving length checking part, I think this is fine.

lib/libusb/libusb10_desc.c
735

I still prefer to move this check closer to the beginning of this function, right after if (bos_cap == NULL || check, as it can avoid unnecessary calling to calloc()/free().

This revision is now accepted and ready to land.Aug 5 2025, 6:06 PM
lib/libusb/libusb10_desc.c
735

Agreed, in general I'd put those kinds of tests before resource allocation etc.