diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index eda206a9..410df8f4 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -26,7 +26,11 @@ NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; for (NSXMLNode *attribute in attributeEnum) { - dictionary[[attribute name]] = [attribute stringValue]; + NSString *attrName = [attribute name]; + if (!attrName) { + continue; + } + dictionary[attrName] = [attribute stringValue]; } return dictionary; } diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 1407d3fa..2a11f247 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -152,8 +152,9 @@ } // Find the appropriate release notes URL. - if (dict[SUAppcastElementReleaseNotesLink]) { - self.releaseNotesURL = [NSURL URLWithString:dict[SUAppcastElementReleaseNotesLink]]; + NSString *releaseNotesString = dict[SUAppcastElementReleaseNotesLink]; + if (releaseNotesString) { + self.releaseNotesURL = [NSURL URLWithString:releaseNotesString]; } else if ([self.itemDescription hasPrefix:@"http://"] || [self.itemDescription hasPrefix:@"https://"]) { // if the description starts with http:// or https:// use that. self.releaseNotesURL = [NSURL URLWithString:self.itemDescription]; } else { @@ -164,12 +165,15 @@ if (deltaDictionaries) { NSMutableDictionary *deltas = [NSMutableDictionary dictionary]; for (NSDictionary *deltaDictionary in deltaDictionaries) { + NSString *deltaFrom = deltaDictionary[SUAppcastAttributeDeltaFrom]; + if (!deltaFrom) continue; + NSMutableDictionary *fakeAppCastDict = [dict mutableCopy]; [fakeAppCastDict removeObjectForKey:SUAppcastElementDeltas]; fakeAppCastDict[SURSSElementEnclosure] = deltaDictionary; SUAppcastItem *deltaItem = [[SUAppcastItem alloc] initWithDictionary:fakeAppCastDict]; - deltas[deltaDictionary[SUAppcastAttributeDeltaFrom]] = deltaItem; + deltas[deltaFrom] = deltaItem; } self.deltaUpdates = deltas; } diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 4271e608..c1e24d7f 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -34,7 +34,7 @@ return self; } -- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; } +- (NSString *__nonnull)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; } - (IBAction)installNow:(id)__unused sender { @@ -57,12 +57,12 @@ self.completionBlock = nil; } -- (NSImage *)applicationIcon +- (NSImage *__nonnull)applicationIcon { return [self.host icon]; } -- (NSString *)titleText +- (NSString *__nonnull)titleText { if ([self.updateItem isCriticalUpdate]) { diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 538869d2..b20efe51 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -219,6 +219,16 @@ [self.download setDestination:self.downloadPath allowOverwrite:YES]; } +/** + * If the update is a package, then it must be signed using DSA. No other verification is done. + * + * If the update is a bundle, then it must meet any one of: + * + * * old and new DSA public keys are the same and valid (it allows change of Code Signing identity), or + * + * * old and new Code Signing identity are the same and valid + * + */ - (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey { BOOL isPackage = NO; @@ -233,7 +243,7 @@ BOOL packageValidated = [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey]; if (!packageValidated) { - SULog(@"DSA signature validation failed. The update will be rejected."); + SULog(@"DSA signature validation of the package failed. The update will be rejected."); } return packageValidated; diff --git a/Sparkle/SUBinaryDeltaApply.m b/Sparkle/SUBinaryDeltaApply.m index 43952df9..d8eef104 100644 --- a/Sparkle/SUBinaryDeltaApply.m +++ b/Sparkle/SUBinaryDeltaApply.m @@ -20,7 +20,7 @@ static BOOL applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFil NSString *patchFile = temporaryFilename(@"apply-binary-delta"); xar_extract_tofile(x, file, [patchFile fileSystemRepresentation]); const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]}; - BOOL success = (bspatch(4, (char **)argv) == 0); + BOOL success = (bspatch(4, argv) == 0); unlink([patchFile fileSystemRepresentation]); return success; } diff --git a/Sparkle/SUBinaryDeltaCommon.m b/Sparkle/SUBinaryDeltaCommon.m index 9bde20c3..ec7fc4e1 100644 --- a/Sparkle/SUBinaryDeltaCommon.m +++ b/Sparkle/SUBinaryDeltaCommon.m @@ -145,7 +145,7 @@ NSData *hashOfFileContents(FTSENT *ent) NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion) { const char *sourcePaths[] = {[path fileSystemRepresentation], 0}; - FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles); + FTS *fts = fts_open(sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles); if (!fts) { perror("fts_open"); return nil; diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 7537e30a..fc5724bd 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -11,7 +11,7 @@ #import "SUGuidedPackageInstaller.h" -static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments) +static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, char* const* arguments) { sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL); BOOL returnValue = YES; @@ -19,7 +19,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" /* AuthorizationExecuteWithPrivileges used to support 10.4+; should be replaced with XPC or external process */ - if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, (char* const*)arguments, NULL) == errAuthorizationSuccess) + if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, arguments, NULL) == errAuthorizationSuccess) #pragma clang diagnostic pop { int status = 0; @@ -55,11 +55,11 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza const char* executableFileSystemRepresentation = [executablePath fileSystemRepresentation]; // Prepare a right allowing script to execute with privileges - AuthorizationItem right; - memset(&right,0,sizeof(right)); - right.name = kAuthorizationRightExecute; - right.value = (void*) executableFileSystemRepresentation; - right.valueLength = strlen(executableFileSystemRepresentation); + AuthorizationItem right = { + .name = kAuthorizationRightExecute, + .value = (char*)executableFileSystemRepresentation, + .valueLength = strlen(executableFileSystemRepresentation), + }; // Package up the single right AuthorizationRights rights; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index a1b87634..f7c3618d 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -100,7 +100,7 @@ typedef struct { return [self.bundle bundlePath]; } -- (NSString *)name +- (NSString *__nonnull)name { NSString *name; @@ -117,7 +117,7 @@ typedef struct { return [[[NSFileManager defaultManager] displayNameAtPath:[self.bundle bundlePath]] stringByDeletingPathExtension]; } -- (NSString *)version +- (NSString *__nonnull)version { NSString *version = [self.bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; if (!version || [version isEqualToString:@""]) @@ -125,7 +125,7 @@ typedef struct { return version; } -- (NSString *)displayVersion +- (NSString *__nonnull)displayVersion { NSString *shortVersionString = [self.bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; if (shortVersionString) @@ -134,7 +134,7 @@ typedef struct { return [self version]; // Fall back on the normal version string. } -- (NSImage *)icon +- (NSImage *__nonnull)icon { // Cache the application icon. NSString *iconPath = [self.bundle pathForResource:[self.bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:@"icns"]; @@ -169,17 +169,25 @@ typedef struct { return ([[NSApplication sharedApplication] activationPolicy] == NSApplicationActivationPolicyAccessory); } -- (NSString *)publicDSAKey +- (NSString *__nullable)publicDSAKey { // Maybe the key is just a string in the Info.plist. NSString *key = [self.bundle objectForInfoDictionaryKey:SUPublicDSAKeyKey]; - if (key) { return key; } + if (key) { + return key; + } // More likely, we've got a reference to a Resources file by filename: NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; - if (!keyFilename) { return nil; } - NSError *ignoreErr = nil; - return [NSString stringWithContentsOfFile:[self.bundle pathForResource:keyFilename ofType:nil] encoding:NSASCIIStringEncoding error:&ignoreErr]; + if (!keyFilename) { + return nil; + } + + NSString *keyPath = [self.bundle pathForResource:keyFilename ofType:nil]; + if (!keyPath) { + return nil; + } + return [NSString stringWithContentsOfFile:keyPath encoding:NSASCIIStringEncoding error:nil]; } - (NSArray *)systemProfile diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index 7a65054c..7317143d 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -30,9 +30,13 @@ NSString *lastPathComponent = [path lastPathComponent]; for (NSString *currentType in typeSelectorDictionary) { + NSString *value = typeSelectorDictionary[currentType]; + assert(value); + if ([currentType length] > [lastPathComponent length]) continue; - if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType]) - return NSSelectorFromString(typeSelectorDictionary[currentType]); + if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType]) { + return NSSelectorFromString(value); + } } return NULL; } diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 6aef7bd2..e9e47404 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -63,12 +63,16 @@ // If this is a background application we need to focus it in order to bring the prompt // to the user's attention. Otherwise the prompt would be hidden behind other applications and // the user would not know why the application was paused. - if ([aHost isBackgroundApplication]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } + if ([aHost isBackgroundApplication]) { + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; + } - if( ![NSApp modalWindow]) // do not prompt if there is is another modal window on screen - { + if (![NSApp modalWindow]) { // do not prompt if there is is another modal window on screen SUUpdatePermissionPrompt *prompt = [[[self class] alloc] initWithHost:aHost systemProfile:profile delegate:d]; - [NSApp runModalForWindow:[prompt window]]; + NSWindow *window = [prompt window]; + if (window) { + [NSApp runModalForWindow:window]; + } } } diff --git a/Sparkle/Sparkle.pch b/Sparkle/Sparkle.pch index ccd8c759..afac8dca 100644 --- a/Sparkle/Sparkle.pch +++ b/Sparkle/Sparkle.pch @@ -8,10 +8,15 @@ #ifdef __OBJC__ +#if !defined(__clang_major__) || __clang_major__ < 7 +#define __nonnull +#define __nullable +#endif + #import #import "SUConstants.h" #import "SUErrors.h" -#define SULocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", [NSBundle bundleWithIdentifier:SUBundleIdentifier] ? [NSBundle bundleWithIdentifier:SUBundleIdentifier] : [NSBundle mainBundle], comment) +#define SULocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", (NSBundle *__nonnull)([NSBundle bundleWithIdentifier:SUBundleIdentifier] ? [NSBundle bundleWithIdentifier:SUBundleIdentifier] : [NSBundle mainBundle]), comment) #endif diff --git a/TestApplication/main.m b/TestApplication/main.m index f858e875..28e50644 100644 --- a/TestApplication/main.m +++ b/TestApplication/main.m @@ -8,7 +8,7 @@ #import -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { - return NSApplicationMain(argc, (const char **)argv); + return NSApplicationMain(argc, argv); }