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

get_string_property() may truncate string on MAC OS #69

Open
tomsor opened this issue Jul 13, 2012 · 5 comments
Open

get_string_property() may truncate string on MAC OS #69

tomsor opened this issue Jul 13, 2012 · 5 comments

Comments

@tomsor
Copy link

tomsor commented Jul 13, 2012

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.

@signal11
Copy link
Owner

I agree with that assessment. Do you want to submit a patch for this?

@tomsor
Copy link
Author

tomsor commented Jul 14, 2012

I don't know how to do this (sorry i am new to github projects contribution). Do i need special rights to do it ?

@signal11
Copy link
Owner

No special rights required. Just send me a pull request, and I will review and then merge it.

https://help.github.com/articles/using-pull-requests/

@signal11
Copy link
Owner

If you don't want to, that's fine too. Let me know and I'll do it myself.

@tomsor
Copy link
Author

tomsor commented Jul 16, 2012

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.

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

No branches or pull requests

2 participants