- native implementations for hidraw/libusb/macOS;
- HID Report Descriptor reconstruction from HIDP_PREPARSED_DATA on Windows;
- unit-tests for some known devices for `hid_winapi_descriptor_reconstruct_pp_data`;
- support for ASAN builds (mainly to check the `hid_winapi_descriptor_reconstruct_pp_data`/its unit-tests;
Commit 5c9f147a07 (#432) replaced a call to strdup with an explicit
memcpy to a buffer on the stack.
However, it incorrectly used the buffer size, instead of the clamped
uevent length, as the argument to memcpy, resulting in reads past the
end of uevent:
Fix this by using uevent_len as the argument to memcpy.
Calling strndupa was considered but abandoned, as it is not standard.
Fixes: 5c9f147a07 (#432)
Fixes: 4779d63d8760
- new API function: `struct hid_device_info * hid_get_device_info(hid_device *dev);` to get `hid_device_info` after the device already opened;
- reused existing implementation on Windows and macOS from enumeration routines to have the implementation;
- refactored libusb implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;
- refactored hidraw implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;
Resolves: #431Closes: #164Closes: #163
- make the behaviour of methods which set hid_error more consistent;
- make the documentation and the implementation of hid_error consistent and safe;
- windows: add global error implementation;
Co-authored-by: Julian Waller <git@julusian.co.uk>
- uhid USB, Bluetooth (standard) and I2C now enumerating
* USB uhid support was added by removing the udev USB endpoint check;
- HID over I2C was excluded before (likely because it didn't exist when
hidraw was developed);
NOTE: This commit does not handle composite HID descriptors
I am interested in adding support for composite descriptors though I still need to find a
device with a composite descriptor to test it correctly.
The implementation idea is similar, as in #125 for macOS.
The open systcall is allowed to return 0 as a valid file descriptor,
and considering it an error breaks environments where unnecessary
fds are closed before executing untrusted processes.
Fixes: #199
Signed-off-by: Marc Zyngier <maz@kernel.org>
Problem reported by the Coverity tool
CID 1042532 (#1 of 1): Unchecked return value from library
(CHECKED_RETURN)2. check_return: Calling function
"fstat(dev->device_handle, &s)" without checking return value. This
library function may fail and return an error code.
Refactor version detection into a function.
Handle versions of form X.Y.Z as well as X.Y.
Don't do workarounds for old kernels if version cannot be detected.
It appears that calls to read() when in non-blocking mode will not set errno
to other than EAGAIN when the a device has been disconnected. Note that
this is the same errno code set when there is simply no data to return.
Make it so that poll() is used, in non-blocking mode, to check the
status of the device. In blocking mode though, poll() is not needed.
Passing product_id=0 will match any product of a given vendor. This patch
makes it also possible to use vendor_id=0 to match any vendor for a given
product id.
Windows code added to Ludovic's patch by Alan Ott.
hid.c: In function 'uses_numbered_reports':
hid.c:126:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
hid.c:143:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
linux/hid.c:83:13: warning: function declaration isn't a prototype [-Wstrict-prototypes]
linux/hid.c: In function 'new_hid_device':
linux/hid.c:83:13: warning: old-style function definition [-Wold-style-definition]
mbstowcs() returns a size_t not an int.
hid.c: In function 'get_device_string':
hid.c:285:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
hid.c:289:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
hid.c:318:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In case of error mbstowcs() returns (size_t) -1
It is not a negative value since mbstowcs() returns a size_t (unsigned)
Fix compiler warning:
hid.c: In function 'utf8_to_wchar_t':
hid.c:105:3: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]