From 921aed0fae5edf477adeb38ad60bbde3248b1a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Tue, 20 Dec 2016 20:32:50 +0100 Subject: [PATCH] Temp vars --- Sparkle/SUBinaryDeltaTool.m | 10 +++++++--- Sparkle/SUPlainInstaller.m | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Sparkle/SUBinaryDeltaTool.m b/Sparkle/SUBinaryDeltaTool.m index 01f07dcf..ac3cdfc0 100644 --- a/Sparkle/SUBinaryDeltaTool.m +++ b/Sparkle/SUBinaryDeltaTool.m @@ -96,21 +96,25 @@ static BOOL runCreateCommand(NSString *programName, NSArray *args) return NO; } + NSString *sourcePath = fileArgs[0]; + NSString *destPath = fileArgs[1]; + NSString *patchPath = fileArgs[2]; + BOOL isDirectory; - if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[0] isDirectory:&isDirectory] || !isDirectory) { + if (![[NSFileManager defaultManager] fileExistsAtPath:sourcePath isDirectory:&isDirectory] || !isDirectory) { printUsage(programName); fprintf(stderr, "Error: before-tree must be a directory\n"); return NO; } - if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[1] isDirectory:&isDirectory] || !isDirectory) { + if (![[NSFileManager defaultManager] fileExistsAtPath:destPath isDirectory:&isDirectory] || !isDirectory) { printUsage(programName); fprintf(stderr, "Error: after-tree must be a directory\n"); return NO; } NSError *createDiffError = nil; - if (!createBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], patchVersion, verbose, &createDiffError)) { + if (!createBinaryDelta(sourcePath, destPath, patchPath, patchVersion, verbose, &createDiffError)) { fprintf(stderr, "%s\n", [createDiffError.localizedDescription UTF8String]); return NO; } diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index d11e3bb8..1f858604 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -45,7 +45,8 @@ SUFileManager *fileManager = [SUFileManager fileManagerWithAuthorizationToolPath:fileOperationToolPath]; // Create a temporary directory for our new app that resides on our destination's volume - NSURL *tempNewDirectoryURL = [fileManager makeTemporaryDirectoryWithPreferredName:[installationURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingString:@" (Incomplete Update)"] appropriateForDirectoryURL:installationURL.URLByDeletingLastPathComponent error:error]; + NSString *preferredName = [installationURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingString:@" (Incomplete Update)"]; + NSURL *tempNewDirectoryURL = [fileManager makeTemporaryDirectoryWithPreferredName:preferredName appropriateForDirectoryURL:installationURL.URLByDeletingLastPathComponent error:error]; if (tempNewDirectoryURL == nil) { SULog(@"Failed to make new temp directory"); return NO; @@ -163,7 +164,10 @@ // Prevent malicious downgrades if (!allowDowngrades) { - if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) { + NSString *hostVersion = [host version]; + NSBundle *bundle = [NSBundle bundleWithPath:path]; + NSString *updateVersion = [bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; + if (!updateVersion || [comparator compareVersion:hostVersion toVersion:updateVersion] == NSOrderedDescending) { NSString *errorMessage = [NSString stringWithFormat:@"For security reasons, updates that downgrade version of the application are not allowed. Refusing to downgrade app from version %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]]; NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; [self finishInstallationToPath:installationPath withResult:NO error:error completionHandler:completionHandler];