Page MenuHomeFreeBSD

libusb: change callback register handler to int
ClosedPublic

Authored by emaste on Dec 13 2025, 3:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Aug 21, 11:14 AM
Unknown Object (File)
Tue, Aug 18, 1:01 PM
Unknown Object (File)
Mon, Aug 17, 3:58 PM
Unknown Object (File)
Mon, Aug 17, 3:21 PM
Unknown Object (File)
Sun, Aug 16, 9:49 PM
Unknown Object (File)
Sun, Aug 16, 9:49 PM
Unknown Object (File)
Sun, Aug 16, 8:26 PM
Unknown Object (File)
Sat, Aug 15, 8:46 PM
Subscribers

Details

Summary

libusb upstream uses int for register handler. This causes some library
user (like pyusb) to assume that we have int in all implementations and
therefore provides a 4 byte storage only. This causes Segmentation
fault as we will right the pointer.

Diff Detail

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

Event Timeline

This revision is now accepted and ready to land.Dec 14 2025, 1:46 AM

This should be fine to recommit now that the so version has been bumped

Oh, I can re-commit this version. Let me bring it back later.

It needs rebase. Do it tomorrow.

The only conflict is on struct libusb_context in lib/libusb/libusb10.h I believe. Any chance you can rebase and push soon?

emaste commandeered this revision.
emaste updated this revision to Diff 184544.
emaste added a reviewer: aokblast.
lib/libusb/libusb10_hotplug.c
376

Won't this mean an underflow will result in two callbacks being assigned id == 1 ?

lib/libusb/libusb10_hotplug.c
376

Yes (this is unchanged from the original commit before rebasing), if the callback is still in use. If the caller registers a callback and then registers & unregisters enough to trigger this wrap.

I plan to commit this version shortly to fix the ABI issue as close as possible in time to the so bump, but will add an XXX comment. The signed integer overflow is also UB.

Add XXX comment. Will be in separate commit with

libusb: Add an XXX comment for possible duplicate callback IDs

If next_callback_id wraps we could end up with two callbacks with the
same ID.  I recommitted the original change despite this issue in order
to fix the libusb API as soon as possible after SHLIB_MAJOR was bumped
in commit 527a82474cb3 (libusb: versioning symbols).

In practice we probably expect a single-digit callback count, and most likely only one or maybe two, so an O(n) loop over the list to check for a duplicate ID should be OK (we're already doing this regularly anyway).

This revision was not accepted when it landed; it landed in state Needs Review.Fri, Aug 21, 2:57 PM
This revision was automatically updated to reflect the committed changes.