git: a793cabb621e - main - libusb: Avoid signed integer overflow UB
Ed Maste <[email protected]>
| Newsgroups | gmane.os.freebsd.devel.cvs.src |
|---|---|
| Message-ID | <6a88abf8.36563.18e65838__30228.6925887287$1787341837$gmane$org@gitrepo.freebsd.org> |
The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=a793cabb621ee33ded7ef25cf8290ee53d2c5e4d commit a793cabb621ee33ded7ef25cf8290ee53d2c5e4d Author: Ed Maste <[email protected]> AuthorDate: 2026-08-21 16:56:08 +0000 Commit: Ed Maste <[email protected]> CommitDate: 2026-08-21 19:49:44 +0000 libusb: Avoid signed integer overflow UB Instead, just reset next_callback_id to 1 at INT_MAX. The potential for duplicate callback IDs remains. Sponsored by: The FreeBSD Foundation --- lib/libusb/libusb10_hotplug.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c index ae7e8d168948..5def972c5ab5 100644 --- a/lib/libusb/libusb10_hotplug.c +++ b/lib/libusb/libusb10_hotplug.c @@ -374,10 +374,15 @@ int libusb_hotplug_register_callback(libusb_context *ctx, handle->devclass = dev_class; handle->fn = cb_fn; handle->user_data = user_data; + CTX_LOCK(ctx); - /* XXX This could result in duplicate callback IDs, and is UB. */ - if ((handle->id = ctx->next_callback_id++) < 0) - handle->id = ctx->next_callback_id = 1; + handle->id = ctx->next_callback_id; + if (ctx->next_callback_id == INT_MAX) { + /* XXX This could result in duplicate callback IDs. */ + ctx->next_callback_id = 1; + } else { + ctx->next_callback_id++; + } CTX_UNLOCK(ctx); HOTPLUG_LOCK(ctx);