Fix crashes when pasting non-text data in wxOSX

Check that conversions succeed before using their results to avoid
crashing if the data on clipboard is in an unexpected format.

Closes #18344.
This commit is contained in:
Tim Kosse
2019-02-12 16:19:18 +01:00
committed by Vadim Zeitlin
parent fb00507fb5
commit dd56499fe9

View File

@@ -469,14 +469,20 @@ bool wxDataObject::GetFromPasteboard( void * pb )
{
// revert the translation and decomposition to arrive at a proper utf8 string again
CFURLRef url = CFURLCreateWithBytes( kCFAllocatorDefault, CFDataGetBytePtr( flavorData ), flavorDataSize, kCFStringEncodingUTF8, NULL );
CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
CFRelease( url );
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
CFRelease( cfString );
CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
wxString path = wxCFStringRef(cfMutableString).AsString();
if (!path.empty())
filenamesPassed += path + wxT("\n");
if ( url )
{
CFStringRef cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
CFRelease( url );
if ( cfString )
{
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
CFRelease( cfString );
CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
wxString path = wxCFStringRef(cfMutableString).AsString();
if (!path.empty())
filenamesPassed += path + wxT("\n");
}
}
}
else
{