ylechelle/OpenUDID — pull request #15 by jamesrz2live (2012-03-28 20:48:26+00:00)
Title: Fixes a crash when unarchiving a malformed archive from the pasteboard

Suppose that an application pollutes the pasteboard by doing something like the following:

// fills the pasteboard with bogus OpenUDID slot "dictionaries".
for(int n=0;n<100;n++)
{
NSString* pbId = [NSString stringWithFormat:@"org.OpenUDID.slot.%d", n];
UIPasteboard* pb = [UIPasteboard pasteboardWithName:pbId create:NO];
if(pb)
[pb setValue:[[NSArray new] autorelease] forPasteboardType:@"org.OpenUDID"];
}

Any application that uses OpenUDID would then crash when it attempts to unarchive one of these values from the pasteboard when doing the frequency check, inside of _getDictFromPasteboard:

OpenUDID.m, line 79:
// Retrieve an NSDictionary from a pasteboard of a given type
// Convenience method to support iOS & Mac OS X
//
+ (NSMutableDictionary*) _getDictFromPasteboard:(id)pboard {
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
id item = [pboard dataForPasteboardType:kOpenUDIDDomain];
#else
id item = [pboard dataForType:kOpenUDIDDomain];
#endif
if (item)
item = [NSKeyedUnarchiver unarchiveObjectWithData:item]; // EXCEPTION THROWN HERE <----

// return an instance of a MutableDictionary
return [NSMutableDictionary dictionaryWithDictionary:(item == nil || [item isKindOfClass:[NSDictionary class]]) ? item : nil];
}

This pull request fixes this problem by surrounding the call to "NSKeyedUnarchiver unarchiveObjectWithData:" with a @try block.