[Lldb-commits] [PATCH] Host::GetOSVersion simplification

Jean-Daniel Dupas devlists at shadowlab.org
Thu Jul 3 13:23:49 PDT 2014


I have a question about that piece of code in Host::GetOSVersion for OS X.

                       CFStringRef product_version_cfstr = (CFStringRef) product_version_value;
                        product_version_str = CFStringGetCStringPtr(product_version_cfstr, kCFStringEncodingUTF8);
                        if (product_version_str != NULL) {
                            if (CFStringGetCString(product_version_cfstr, buffer, 256, kCFStringEncodingUTF8))
                                product_version_str = buffer;

If CFStringGetCStringPtr() returns NULL, the call to CFStringGetCString() which is perfectly valid will never be executed.
If it returns a valid pointer, we discard the result by calling CFStringGetCString().

And if we reverse the check and fallback to CFStringGetCString() only when CFStringGetCStringPtr returns NULL, we will end up with a reference to a freed string at the time we try to parse it (as the owner of the string is property_list)

Anyway, here is a patch that replaces that whole function by 4 lines of Obj-C. As a bonus, it removes a call to CFURLCreateDataAndPropertiesFromResource() which is now deprecated.

Please review. Thanks
-- Jean-Daniel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: osvers.patch
Type: application/octet-stream
Size: 3710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140703/8ed6d9f6/attachment.obj>

More information about the lldb-commits mailing list