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

jingham at apple.com jingham at apple.com
Thu Jul 3 15:04:11 PDT 2014


We originally decided to avoid Foundation if we could, though I don't remember why.  If we don't object to using Foundation on the Mac then this is fine.  

Anybody else have an opinion about that?

Jim

> On Jul 3, 2014, at 1:23 PM, Jean-Daniel Dupas <devlists at shadowlab.org> wrote:
> 
> Hello,
> 
> 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
> 
> 
> 
> <osvers.patch>_______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits




More information about the lldb-commits mailing list