-
Notifications
You must be signed in to change notification settings - Fork 901
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
get_string_property() may truncate string on MAC OS #69
Comments
I agree with that assessment. Do you want to submit a patch for this? |
I don't know how to do this (sorry i am new to github projects contribution). Do i need special rights to do it ? |
No special rights required. Just send me a pull request, and I will review and then merge it. |
If you don't want to, that's fine too. Let me know and I'll do it myself. |
I prefer that you do it this time, I don't have my development computer this week. I will try to make a pull request next time since I have other small fixes to share. |
The function get_string_property() calls CFStringGetBytes() with 7th parameter 'maxBufLen' set to 'len' which is the number of characters of the 'buf'.
But according to MAC OS specification :
maxBufLen
The size of buffer and the maximum number of bytes that can be written to it.
see :
https://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html
So maxBufLen should be set to len * sizeof(wchar_t) to indicate properly the real size in bytes of the buffer.
get_string_property() is used by get_serial_number(), get_manufacturer_string() and get_product_string() with a len of 256 (wchar_t) characters.
I suppose that CFStringGetBytes() will truncate or even fail if it cannot fit the buffer, which could happen if there are more than 64 characters to convert (which in that case would require more than 64 * 4 bytes of buffer size for UTF-32 conversion).
Additionally specification says the 8th parameter 'usedBufLen' may be NULL "if you are not interested in this information". I suggest removing the local variable 'used_buf_len' and passing NULL instead.
The text was updated successfully, but these errors were encountered: