[libhid-discuss] Bug in hid_opening: hid_compare_usb_device()

Warren Jasper wjasper at tx.ncsu.edu
Mon Feb 4 18:36:57 UTC 2008


Problem:
  If there is a device with product ID 0x7f on the bus, and the matched 
product
  id is 0x7d,  (where clearly 0x7f != 0x7d),  hid_compare_usb_device() 
will return
  true (that there is a match).

Reason:
   In hid_compare_usb_device(),   The logic:

         if (dev->descriptor.idVendor & match->vendor_id) == 
match->vendor_id) {

and

  if ((dev->descriptor.idProduct & match->product_id) == 
match->product_id) {

are wrong.  They should read

         if (dev->descriptor.idVendor  == match->vendor_id) {

        if (dev->descriptor.idProduct  == match->product_id) {

And here is why.    Say dev->descriptor.idProduct = 0x7f and 
match->product_id = 0x7d.
    (0x7f & 0x7d) == 0x7d

The only problem is that I'm trying to find a 0x7d product, and libhid 
is saying that 0x7f is
a match and trying to opening it.   If 0x7f is already open, a lot of 
other weird and unexpected things can happen.

Warren



More information about the libhid-discuss mailing list