Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hidapi/linux: fix uninitialized variable #692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0xilis
Copy link

@0xilis 0xilis commented Sep 15, 2024

In parse_hid_vid_pid_from_uevent_path, if the file is less than 1024 bytes somehow, the read() call will return the size of the file and pass the if (res < 0) check, but the leftover bytes that were not copied to from the file will remain uninitialized. This commit fixed it by initializing the buffer with 0.

@mcuee mcuee added the hidraw Related to Linux/hidraw backend label Sep 15, 2024
@Youw
Copy link
Member

Youw commented Sep 15, 2024

  1. I can't even recall it C supports = {0} initialisation by the standard.

  2. The function ensures that the string is NULL-terminated and that buffer is always threated as a c-string, so uninitialized part of the memory would never be read. Unless you've found a an excemple where it actually fails. Did you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hidraw Related to Linux/hidraw backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants