From: Jay Freeman (saurik) Date: Wed, 9 Feb 2011 21:35:07 +0000 (-0800) Subject: Support NULL Cytore return in PackageFind(). X-Git-Tag: v1.1.0%b1~364 X-Git-Url: https://git.saurik.com/cydia.git/commitdiff_plain/c65611b940099e8762aa18bd34d75799898e77bd Support NULL Cytore return in PackageFind(). --- diff --git a/MobileCydia.mm b/MobileCydia.mm index cc0d9788..fe48f969 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1427,7 +1427,7 @@ struct MetaValue : static Cytore::File MetaFile_; // }}} // Cytore Helper Functions {{{ -static PackageValue *PackageFind(const char *name, size_t length) { +static PackageValue *PackageFind(const char *name, size_t length, bool *fail = NULL) { SplitHash nhash = { hashlittle(name, length) }; PackageValue *metadata; @@ -1437,6 +1437,14 @@ static PackageValue *PackageFind(const char *name, size_t length) { *offset = MetaFile_.New(length + 1); metadata = &MetaFile_.Get(*offset); + if (metadata == NULL) { + if (fail != NULL) + *fail = true; + + metadata = new PackageValue(); + memset(metadata, 0, sizeof(*metadata)); + } + memcpy(metadata->name_, name, length + 1); metadata->nhash_ = nhash.u16[1]; } else { @@ -1452,13 +1460,15 @@ static PackageValue *PackageFind(const char *name, size_t length) { } static void PackageImport(const void *key, const void *value, void *context) { + bool &fail(*reinterpret_cast(context)); + char buffer[1024]; if (!CFStringGetCString((CFStringRef) key, buffer, sizeof(buffer), kCFStringEncodingUTF8)) { NSLog(@"failed to import package %@", key); return; } - PackageValue *metadata(PackageFind(buffer, strlen(buffer))); + PackageValue *metadata(PackageFind(buffer, strlen(buffer), &fail)); NSDictionary *package((NSDictionary *) value); if (NSNumber *subscribed = [package objectForKey:@"IsSubscribed"]) @@ -9463,11 +9473,15 @@ int main(int argc, char *argv[]) { _pooled _trace(); if (Packages_ != nil) { - CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, NULL); + bool fail(false); + CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, &fail); _trace(); - [Metadata_ removeObjectForKey:@"Packages"]; - Packages_ = nil; - Changed_ = true; + + if (!fail) { + [Metadata_ removeObjectForKey:@"Packages"]; + Packages_ = nil; + Changed_ = true; + } } Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];