[libhid-discuss] Patch: hid_compare_usb_device returns false positives

Charles Lepple clepple at ghz.cc
Wed Aug 27 00:16:41 UTC 2008


It's a known "feature".

The original intent was to have bitmasks to match similar product/ 
vendor IDs, but somewhere along the line it got over-optimized into  
what you see now.

If you want your code to work with libhid as it is shipped in various  
distributions, you can use the custom matcher function. This has been  
discussed before - see the archives.

On Aug 26, 2008, at 3:43 PM, Christopher wrote:

> hid_compare_usb_device() returns false positives for devices with  
> similar vendor or product ids.
> In the current code we check:
> "if ((dev->descriptor.idProduct & match->product_id) == match- 
> >product_id)"
> However, "(dev->descriptor.idProduct & match->product_id) == match- 
> >product_id" does not imply that dev->descriptor.idProduct == match- 
> >product_id.
> Example:
> idProduct = 0x0011
> product_id = 0x0001
> idProduct & product_id == 0x0001
>
> Let me know if the patch is not formatted properly,
> Christopher Berner
>
> Index: src/hid_opening.c
> ===================================================================
> --- src/hid_opening.c	(revision 362)
> +++ src/hid_opening.c	(working copy)
> @@ -77,14 +77,14 @@
>
>    TRACE("inspecting vendor ID...");
>    if (dev->descriptor.idVendor > 0 &&
> -      (dev->descriptor.idVendor & match->vendor_id) == match- 
> >vendor_id) {
> +      (dev->descriptor.idVendor == match->vendor_id)) {
>        TRACE("match on vendor ID: 0x%04x.", dev->descriptor.idVendor);
>        ret |= USB_MATCH_VENDOR;
>    }
>    else TRACE("no match on vendor ID.");
>
>    TRACE("inspecting product ID...");
> -  if ((dev->descriptor.idProduct & match->product_id) == match- 
> >product_id) {
> +  if ((dev->descriptor.idProduct == match->product_id)) {
>        TRACE("match on product ID: 0x%04x.", dev- 
> >descriptor.idProduct);
>        ret |= USB_MATCH_PRODUCT;
>    }
> _______________________________________________
> libhid-discuss mailing list
> libhid-discuss at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss



More information about the libhid-discuss mailing list