hidapi icon indicating copy to clipboard operation
hidapi copied to clipboard

Win32: modified hid_winapi_get_container_id() for consistency

Open DJm00n opened this issue 3 years ago • 1 comments

Make use of hid_internal_get_devnode_property() method.

DJm00n avatar Jul 15 '22 18:07 DJm00n

This method is not meant to be called frequently so I think we can disregard this 8 byte malloc.

DJm00n avatar Jul 16 '22 17:07 DJm00n

Actually, there is one more issue with the new implementation: no more explicit check for the buffer size. It is highly unlikely that WinAPI will report a DEVPROP_TYPE_GUID but len of smaller than sizeof(GUID), but I like it much better if there is no implicit assumptions in the code.

Youw avatar Aug 13 '22 16:08 Youw

It is highly unlikely that WinAPI will report a DEVPROP_TYPE_GUID but len of smaller than sizeof(GUID)

According to the documentation, this should not be a problem:

Property data type Property value size requirement
A fixed-length base-data-type value The specified size of the supplied data must be the number of bytes in the base data type.

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/property-value-requirements

Set the PropertyType parameter to DEVPROP_TYPE_GUID, set the PropertyBuffer parameter to a pointer to a buffer that contains a GUID value, and set the PropertyBufferSize parameter to sizeof(GUID).

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/devprop-type-guid

DJm00n avatar Aug 15 '22 16:08 DJm00n

According to the documentation

Unfortunately I've personally seen cases when WinAPI didn't behave as per documentation.

My consern stands:

  • when we pass a buffer that is bigger than an API uses - that's fine;
  • if we ask how large buffer API needs, allocate memory for it, and then don't actually check its size and try to read it - that is a potential issue;

Youw avatar Aug 15 '22 18:08 Youw