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
uninitialized strings on windows hid.c #315
Comments
Are you sure the memset is needed? calloc both allocates and zeros. |
Mmmm... Now that I read the definition on cppreference, indeed, calloc should already be doing that. What I can assert is that with these two changes, I got the problem fixed on Mixxx. Maybe it turns out it was simply the string initialization. |
Further, free(NULL) is perfectly valid in C. |
Ok, let's start again. I was wrong with the "memset" requirement (and what it came out from that, namely the problems with free). If calloc is working as expected with visual studio, then that should not be the problem I was experiencing. Now, there is the second change, the wstr[0] = 0x0000; |
Maybe the platform code is broken then. Can you do the same for all the strings and submit a patch? |
You mean, this? Edit: attached file |
I mean submit it as a pull request, and not just for the serial number string, for all the strings. Also, put the added line after the comment (rather than before) |
There is an unitialized memory in windows/hid.c that can cause garbage output (and maybe even crashes).
Basically, what has been detected is that on devices that do not report some of the HidD_Getxxxx() methods (i.e. that res = FALSE) is that random text appears on serial_number, manufacturer_string and product_string, basically because it's never filled.
Also, given that we also have:
free(d->serial_number);
free(d->manufacturer_string);
free(d->product_string);
it could perfectly crash in this situation.
Additionally, I add wstr[0] = 0x0000 in case for whatever reason the call to the method returned TRUE but didn't touch the string.
@392:
tmp = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
+++ // Initialize all memory to zero:
+++ memset(tmp, 0, sizeof(struct hid_device_info));
And then:
@425:
+++ wstr[0] = 0x0000;
/* Serial Number */
res = HidD_GetSerialNumberString(write_handle, wstr, sizeof(wstr));
The text was updated successfully, but these errors were encountered: