Re: git: 1c2263b68397 - main - libusb: Validate arguments before dereferencing the hotplug context

From: Harry Schmalzbauer <freebsd_at_omnilan.de>
Date: Sun, 01 Nov 2026 12:20:22 UTC
On 2026-08-24 03:30, ShengYi Hung wrote:
> The branch main has been updated by aokblast:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=1c2263b683977ebab3d9a6448268ad810ceeec70
>
> commit 1c2263b683977ebab3d9a6448268ad810ceeec70
> Author:     yuvrajnode <yuvrajsinghrock1221@gmail.com>
> AuthorDate: 2026-08-23 07:15:49 +0000
> Commit:     ShengYi Hung <aokblast@FreeBSD.org>
> CommitDate: 2026-08-24 01:29:52 +0000
>
>      libusb: Validate arguments before dereferencing the hotplug context
>      
>      libusb_hotplug_register_callback() resolves its context with
>      GET_CONTEXT() and then immediately reads ctx->no_discovery and
>      ctx->usb_event_mode, but only checks "ctx == NULL" afterwards.
>      
>      GET_CONTEXT() falls back to usbi_default_context, which is NULL before
>      libusb_init() and is reset to NULL by libusb_exit().  An application
>      that calls libusb_hotplug_register_callback(NULL, ...) without an
>      initialised default context therefore crashes on the ctx->no_discovery
>      read, instead of getting the LIBUSB_ERROR_INVALID_PARAM the existing
>      guard was clearly written to return.
>      
>      Move the argument validation ahead of the first dereference.  None of
>      the validated arguments depend on the context, so no other ordering
>      constraint is affected.
>      
>      Signed-off-by: yuvrajnode <yuvrajsinghrock1221@gmail.com>
>      Reviewed by:    aokblast
>      MFC after:      2 weeks
>      Pull Request:   https://github.com/freebsd/freebsd-src/pull/2384
>      Closes:         https://github.com/freebsd/freebsd-src/pull/2384
> ---


Hello,

do you still plan to MFC this
(1c2263b68397 - main - libusb: Validate arguments before dereferencing 
the hotplug context)?

I guess these might be valuable MFC candidates too:
2879c818e553 - main - libusb: implement libusb_set_option
6bda9f26d2ed - main - libusb: change callback register handler to int
fc3e8434a61f - main - libusb: Fix NULL dereference when a hotplug 
callback deregisters itself

Probably Ed's too?
250db717b24d libusb: Add an XXX comment for possible duplicate callback IDs
a793cabb621e libusb: Avoid signed integer overflow UB


Thanks,

-harry