From 95398cd26fad4753e72b10e1394c0b8477cac3f8 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 09:28:41 -0700 Subject: [PATCH 1/8] Fixed a no-autorelease-pool leak. --- SUPipedUnarchiver.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index 3a2e4cf3..5c82dbc8 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -48,11 +48,12 @@ { // *** GETS CALLED ON NON-MAIN THREAD!!! - SULog(@"Extracting %@ using '%@'",archivePath,command); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; FILE *fp = NULL, *cmdFP = NULL; + SULog(@"Extracting %@ using '%@'",archivePath,command); + // Get the file size. #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize]; @@ -98,7 +99,7 @@ reportError: finally: if (fp) fclose(fp); - [pool drain]; + [pool release]; } - (void)extractTAR From fc725cce019acb1f069f64aaee198f5dbe80988a Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 10:29:52 -0700 Subject: [PATCH 2/8] Background updates would never get scheduled when the net's down. --- SUUpdater.m | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/SUUpdater.m b/SUUpdater.m index 9bd9ced8..82aed759 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -259,10 +259,8 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault isNetworkReachable = NO; } - if( isNetworkReachable ) - { - [self performSelectorOnMainThread: @selector(checkForUpdatesWithDriver:) withObject: inDriver waitUntilDone: NO]; - } + // If the network's not reachable, we pass a nil driver into checkForUpdatesWithDriver, which will then reschedule the next update so we try again later. + [self performSelectorOnMainThread: @selector(checkForUpdatesWithDriver:) withObject: isNetworkReachable ? inDriver : nil waitUntilDone: NO]; [pool release]; NS_HANDLER @@ -274,12 +272,6 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault - (void)checkForUpdatesInBackground { - if( [delegate respondsToSelector: @selector(updaterMayCheckForUpdates:)] && ![delegate updaterMayCheckForUpdates: self] ) - { - [self scheduleNextUpdateCheck]; - return; - } - // Background update checks should only happen if we have a network connection. // Wouldn't want to annoy users on dial-up by establishing a connection every // hour or so: @@ -316,7 +308,21 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault [host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey]; [self didChangeValueForKey:@"lastUpdateCheckDate"]; - driver = [d retain]; + if( [delegate respondsToSelector: @selector(updaterMayCheckForUpdates:)] && ![delegate updaterMayCheckForUpdates: self] ) + { + [self scheduleNextUpdateCheck]; + return; + } + + driver = [d retain]; + + // If we're not given a driver at all, just schedule the next update check and bail. + if (!driver) + { + [self scheduleNextUpdateCheck]; + return; + } + NSURL* theFeedURL = [self parameterizedFeedURL]; if( theFeedURL ) // Use a NIL URL to cancel quietly. [driver checkForUpdatesAtURL: theFeedURL host:host]; From 613b759077e5b66cc0fc80f1cafa043ddf4ada69 Mon Sep 17 00:00:00 2001 From: Brittany Tarvin Date: Mon, 17 Oct 2011 14:30:00 -0500 Subject: [PATCH 3/8] Fixed issues that led to crashes on Mac OS X 10.7 Lion. These fixes remove the use of the File Manager API that was causing crashes on Lion. This should resolve issue #827357. We are now using NSFileManager instead of the older File Manager API, but only on 10.6 and later. These changes should work for those targeting 10.4, but will allow users running 10.7 to still update without crashing. --- SUDiskImageUnarchiver.m | 27 ++++++++++------ SUPlainInstallerInternals.m | 64 +++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 25 deletions(-) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 7bc37b6a..80c83d29 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -65,15 +65,24 @@ mountedSuccessfully = YES; // Now that we've mounted it, we need to copy out its contents. - FSRef srcRef, dstRef; - OSStatus err; - err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL); - if (err != noErr) goto reportError; - err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL); - if (err != noErr) goto reportError; - - err = FSCopyObjectSync(&srcRef, &dstRef, (CFStringRef)mountPointName, NULL, kFSFileOperationSkipSourcePermissionErrors); - if (err != noErr) goto reportError; + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { + // On 10.6 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357). + NSFileManager *manager = [[NSFileManager alloc] init]; + if (![manager copyItemAtPath:mountPoint toPath:[archivePath stringByDeletingLastPathComponent] error:NULL]) { + goto reportError; + } + } + else { + FSRef srcRef, dstRef; + OSStatus err; + err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL); + if (err != noErr) goto reportError; + err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL); + if (err != noErr) goto reportError; + + err = FSCopyObjectSync(&srcRef, &dstRef, (CFStringRef)mountPointName, NULL, kFSFileOperationSkipSourcePermissionErrors); + if (err != noErr) goto reportError; + } [self performSelectorOnMainThread:@selector(notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO]; goto finally; diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index bdde4581..630ad663 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -461,26 +461,58 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza err = FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &dstDirRef, NULL); if (err == noErr && hadFileAtDest) - { - err = FSMoveObjectSync(&dstRef, &tmpDirRef, (CFStringRef)[tmpPath lastPathComponent], &movedRef, 0); - } - if (err != noErr && hadFileAtDest) - { - if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; - return NO; + { + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) + { + NSFileManager *manager = [[NSFileManager alloc] init]; + BOOL success = [manager moveItemAtPath:dst toPath:tmpPath error:error]; + if (!success && hadFileAtDest) + { + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + return NO; + } + + } else { + err = FSMoveObjectSync(&dstRef, &tmpDirRef, (CFStringRef)[tmpPath lastPathComponent], &movedRef, 0); + if (err != noErr && hadFileAtDest) + { + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + return NO; + } + } } + err = FSPathMakeRef((UInt8 *)[src fileSystemRepresentation], &srcRef, NULL); if (err == noErr) - err = FSCopyObjectSync(&srcRef, &dstDirRef, (CFStringRef)[dst lastPathComponent], NULL, 0); - if (err != noErr) { - // We better move the old version back to its old location - if( hadFileAtDest ) - FSMoveObjectSync(&movedRef, &dstDirRef, (CFStringRef)[dst lastPathComponent], &movedRef, 0); - if (error != NULL) - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't copy %@ to %@.", src, dst] forKey:NSLocalizedDescriptionKey]]; - return NO; + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) + { + NSFileManager *manager = [[NSFileManager alloc] init]; + BOOL success = [manager copyItemAtPath:src toPath:dst error:error]; + if (!success) + { + // We better move the old version back to its old location + if( hadFileAtDest ) + success = [manager moveItemAtPath:tmpPath toPath:dst error:error]; + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; + return NO; + + } + } else { + err = FSCopyObjectSync(&srcRef, &dstDirRef, (CFStringRef)[dst lastPathComponent], NULL, 0); + if (err != noErr) + { + // We better move the old version back to its old location + if( hadFileAtDest ) + FSMoveObjectSync(&movedRef, &dstDirRef, (CFStringRef)[dst lastPathComponent], &movedRef, 0); + if (error != NULL) + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't copy %@ to %@.", src, dst] forKey:NSLocalizedDescriptionKey]]; + return NO; + } + } } // If the currently-running application is trusted, the new From 268ea201dad73e7000840c57961ff2a757280bdc Mon Sep 17 00:00:00 2001 From: Brittany Tarvin Date: Thu, 20 Oct 2011 09:52:02 -0500 Subject: [PATCH 4/8] Fixed leaks with NSFileManager --- SUDiskImageUnarchiver.m | 2 +- SUPlainInstallerInternals.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 80c83d29..56217715 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -67,7 +67,7 @@ // Now that we've mounted it, we need to copy out its contents. if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { // On 10.6 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357). - NSFileManager *manager = [[NSFileManager alloc] init]; + NSFileManager *manager = [[[NSFileManager alloc] init] autorelease]; if (![manager copyItemAtPath:mountPoint toPath:[archivePath stringByDeletingLastPathComponent] error:NULL]) { goto reportError; } diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index 630ad663..15eb16b4 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -464,7 +464,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { - NSFileManager *manager = [[NSFileManager alloc] init]; + NSFileManager *manager = [[[NSFileManager alloc] init] autorelease]; BOOL success = [manager moveItemAtPath:dst toPath:tmpPath error:error]; if (!success && hadFileAtDest) { @@ -489,7 +489,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { - NSFileManager *manager = [[NSFileManager alloc] init]; + NSFileManager *manager = [[[NSFileManager alloc] init] autorelease]; BOOL success = [manager copyItemAtPath:src toPath:dst error:error]; if (!success) { From 5457476e4a3ee0f81f804ed33da1570863affa59 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 27 Oct 2011 21:59:45 -0700 Subject: [PATCH 5/8] Fixes #109: Error extracting dmg archives --- SUDiskImageUnarchiver.m | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 80c83d29..063624da 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -67,10 +67,28 @@ // Now that we've mounted it, we need to copy out its contents. if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { // On 10.6 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357). - NSFileManager *manager = [[NSFileManager alloc] init]; - if (![manager copyItemAtPath:mountPoint toPath:[archivePath stringByDeletingLastPathComponent] error:NULL]) { - goto reportError; - } + NSFileManager *manager = [[[NSFileManager alloc] init] autorelease]; + NSError *error = nil; + NSArray *contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error]; + if (error) + { + SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error); + goto reportError; + } + + for (NSString *fileItem in contents) + { + NSString *fromPath = [mountPoint stringByAppendingPathComponent:fileItem]; + NSString *toPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:fileItem]; + + SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath); + + if (![manager copyItemAtPath:fromPath toPath:toPath error:&error]) + { + SULog(@"Couldn't copy item: %@", error); + goto reportError; + } + } } else { FSRef srcRef, dstRef; From 55eed9efd84c4a2163a3e2b86c8d9b68a243fb6b Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Nov 2011 10:27:04 -0700 Subject: [PATCH 6/8] Fixes #113: Need to check isReadableFileAtPath: when copying out DMG contents --- SUDiskImageUnarchiver.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 6dcf92bc..a905ee6b 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -83,6 +83,10 @@ NSString *fromPath = [mountPoint stringByAppendingPathComponent:item]; NSString *toPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item]; + // We skip any files in the DMG which are not readable. + if (![manager isReadableFileAtPath:fromPath]) + continue; + SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath); if (![manager copyItemAtPath:fromPath toPath:toPath error:&error]) From 095d223e70304d07cb32f703025d1cff35edfd55 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 9 Nov 2011 20:53:18 -0800 Subject: [PATCH 7/8] Fixes #116: Update error: Can't make a temporary directory --- SUBasicUpdateDriver.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 158d271b..344dbf00 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -163,8 +163,17 @@ tempDir = [[[host appSupportPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]] retain]; } + // Create the temporary directory if necessary. #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil]; + BOOL success = YES; + NSEnumerator *pathComponentEnumerator = [[tempDir pathComponents] objectEnumerator]; + NSString *pathComponentAccumulator = @""; + NSString *currentPathComponent; + while ((currentPathComponent = [pathComponentEnumerator nextObject])) { + pathComponentAccumulator = [pathComponentAccumulator stringByAppendingPathComponent:currentPathComponent]; + if ([[NSFileManager defaultManager] fileExistsAtPath:pathComponentAccumulator]) continue; + success &= [[NSFileManager defaultManager] createDirectoryAtPath:pathComponentAccumulator attributes:nil]; + } #else BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL]; #endif From aeeae26d1caf1f8b01c9bbd3b5d063c073e0d60f Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 9 Nov 2011 21:17:47 -0800 Subject: [PATCH 8/8] Critical security patch--re-enabling signature and downgrade checking. When merging Uli Kusterer's branch, we left enabled a preprocessor flag that would disable DSA checking and downgrade prevention. That should not have been merged into master. My apologies to the community for not noticing this sooner. --- SUConstants.h | 4 ++-- SUUpdater.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SUConstants.h b/SUConstants.h index b276589c..4ef1ebb4 100644 --- a/SUConstants.h +++ b/SUConstants.h @@ -15,11 +15,11 @@ // ----------------------------------------------------------------------------- // Turn off DSA signature check (practically invites man-in-the-middle attacks): -#define ENDANGER_USERS_WITH_INSECURE_UPDATES 1 +#define ENDANGER_USERS_WITH_INSECURE_UPDATES 0 // Sparkle usually doesn't allow downgrades as they're usually accidental, but // if your app has a downgrade function or URL handler, turn this on: -#define PERMIT_AUTOMATED_DOWNGRADES 1 +#define PERMIT_AUTOMATED_DOWNGRADES 0 // If your app file on disk is named "MyApp 1.1b4", Sparkle usually updates it // in place, giving you an app named 1.1b4 that is actually 1.2. Turn the diff --git a/SUUpdater.m b/SUUpdater.m index 82aed759..7d426118 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -31,8 +31,8 @@ - (void)updateDriverDidFinish:(NSNotification *)note; - (NSURL *)parameterizedFeedURL; --(void) notifyWillShowAlert; --(void) notifyDidShowAlert; +-(void) notifyWillShowModalAlert; +-(void) notifyDidShowModalAlert; @end