From 53983d9452367de6109c25c1d8bdb2720ec98c3c Mon Sep 17 00:00:00 2001 From: Jerry Krinock Date: Fri, 17 Jun 2016 14:42:44 -0700 Subject: [PATCH 1/3] The following changes were made to clear warnings from static analyzer in Xcode 8: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • In ConfigCommon.xcconfig, removed references to CLANG_WARN_OBJC_RECEIVER_WEAK and -Wno-receiver-is-weak, because apparently these had been deprecated and are now no longer recognized. • In SUAppcast.m, changed to method which can accept nil. • In SUOperatingSystem.h, added a check for nil which probably never happens. • In SUUpdateAlert.m, swapped receiver with parameter in -isEqualToString, 3 places, so that nonnull parameter could never be nil. • In SUUpdater.m, added NSLocalizedString() wrappers around 8 recently-added (in the last few years, I think) user-facing warning strings. --- Configurations/ConfigCommon.xcconfig | 3 +-- Sparkle/SUAppcast.m | 2 +- Sparkle/SUOperatingSystem.m | 13 ++++++++----- Sparkle/SUUpdateAlert.m | 2 +- Sparkle/SUUpdater.m | 16 ++++++++-------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index cd1773b9..c4cc79c5 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -52,7 +52,6 @@ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES -CLANG_WARN_OBJC_RECEIVER_WEAK = YES CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES CLANG_WARN_UNREACHABLE_CODE = YES @@ -88,4 +87,4 @@ CLANG_ENABLE_MODULES[sdk=macosx10.8] = NO WARNING_CFLAGS_EXTRA = -Wno-custom-atomic-properties -Wno-implicit-atomic-properties // Turn on all warnings, then disable a few which are almost impossible to avoid -WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wno-auto-import $(WARNING_CFLAGS_EXTRA) +WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import $(WARNING_CFLAGS_EXTRA) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index c7e8738c..9a2185c7 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -128,7 +128,7 @@ if (!attrName) { continue; } - [dictionary setObject:[attribute stringValue] forKey:attrName]; + [dictionary setValue:[attribute stringValue] forKey:attrName]; } return dictionary; } diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index 2d528027..ada6259b 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -20,11 +20,14 @@ { NSOperatingSystemVersion version = { 0, 0, 0 }; NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil]; - NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]]; - NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; - version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; - version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; - version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; + NSURL *url = [coreServices URLByAppendingPathComponent:@"SystemVersion.plist"] ; + if (url) { + NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:url]; + NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; + version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; + version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; + version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; + } return version; } #endif diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 39698693..3589ffd3 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -260,7 +260,7 @@ { NSURL *requestURL = request.URL; NSString *scheme = requestURL.scheme; - BOOL whitelistedSafe = [@"http" isEqualToString:scheme] || [@"https" isEqualToString:scheme] || [@"about:blank" isEqualToString:requestURL.absoluteString]; + BOOL whitelistedSafe = [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"] || [requestURL.absoluteString isEqualToString:@"about:blank"]; // Do not allow redirects to dangerous protocols such as file:// if (!whitelistedSafe) { diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 83f61422..255b2da5 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -128,15 +128,15 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if (!hasPublicDSAKey) { if (!isMainBundle) { - [self showAlertText:@"Insecure update error!" - informativeText:@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information."]; + [self showAlertText:NSLocalizedString(@"Insecure update error!", nil) + informativeText:NSLocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; } else { if (!hostIsCodeSigned) { - [self showAlertText:@"Insecure update error!" - informativeText:@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information."]; + [self showAlertText:NSLocalizedString(@"Insecure update error!", nil) + informativeText:NSLocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; } else if (!servingOverHttps) { - [self showAlertText:@"Insecure update error!" - informativeText:@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information."]; + [self showAlertText:NSLocalizedString(@"Insecure update error!", nil) + informativeText:NSLocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; } } } @@ -145,8 +145,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if (!servingOverHttps) { BOOL atsExceptionsExist = nil != [self.host objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; if (isMainBundle && !atsExceptionsExist) { - [self showAlertText:@"Insecure feed URL is blocked in macOS 10.11" - informativeText:[NSString stringWithFormat:@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", [feedURL absoluteString]]]; + [self showAlertText:NSLocalizedString(@"Insecure feed URL is blocked in macOS 10.11", nil) + informativeText:[NSString stringWithFormat:NSLocalizedString(@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", nil), [feedURL absoluteString]]]; } else if (!isMainBundle) { SULog(@"WARNING: Serving updates over HTTP may be blocked in macOS 10.11. Please change the feed URL (%@) to use HTTPS. For more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", feedURL); } From 7892e41b27ce468af372f1e95989eb45e6e37893 Mon Sep 17 00:00:00 2001 From: Jerry Krinock Date: Fri, 17 Jun 2016 20:23:32 -0700 Subject: [PATCH 2/3] Fix for warning in in SUAppcast.m now tests for nil instead of using setValue:forKey: --- Sparkle/SUAppcast.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 9a2185c7..d4f32fd9 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -128,7 +128,10 @@ if (!attrName) { continue; } - [dictionary setValue:[attribute stringValue] forKey:attrName]; + NSString *stringValue = [attribute stringValue]; + if (stringValue) { + [dictionary setObject:stringValue forKey:attrName]; + } } return dictionary; } From 33907ec4ed8649bfd58a09f01accdd843fd8c071 Mon Sep 17 00:00:00 2001 From: Jerry Krinock Date: Fri, 17 Jun 2016 22:24:43 -0700 Subject: [PATCH 3/3] =?UTF-8?q?=E2=80=A2=20In=20SUUpdater.m,=20use=20SULoc?= =?UTF-8?q?alizedString=20macro=20instead=20of=20NSLocalizedString.=20?= =?UTF-8?q?=E2=80=A2=20In=20SUOperatingSystem.m,=20assert=20instead=20of?= =?UTF-8?q?=20test=20for=20nil=20URL.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sparkle/SUOperatingSystem.m | 15 +++++++-------- Sparkle/SUUpdater.m | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Sparkle/SUOperatingSystem.m b/Sparkle/SUOperatingSystem.m index ada6259b..10993585 100644 --- a/Sparkle/SUOperatingSystem.m +++ b/Sparkle/SUOperatingSystem.m @@ -20,14 +20,13 @@ { NSOperatingSystemVersion version = { 0, 0, 0 }; NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil]; - NSURL *url = [coreServices URLByAppendingPathComponent:@"SystemVersion.plist"] ; - if (url) { - NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:url]; - NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; - version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; - version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; - version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; - } + NSURL *url = [coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]; + assert(url != nil); + NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:url]; + NSArray *components = [ [dictionary objectForKey: @"ProductVersion"] componentsSeparatedByString:@"."]; + version.majorVersion = components.count > 0 ? [ [components objectAtIndex:0] integerValue] : 0; + version.minorVersion = components.count > 1 ? [ [components objectAtIndex:1] integerValue] : 0; + version.patchVersion = components.count > 2 ? [ [components objectAtIndex:2] integerValue] : 0; return version; } #endif diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 255b2da5..22a71bec 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -128,15 +128,15 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if (!hasPublicDSAKey) { if (!isMainBundle) { - [self showAlertText:NSLocalizedString(@"Insecure update error!", nil) - informativeText:NSLocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; } else { if (!hostIsCodeSigned) { - [self showAlertText:NSLocalizedString(@"Insecure update error!", nil) - informativeText:NSLocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; } else if (!servingOverHttps) { - [self showAlertText:NSLocalizedString(@"Insecure update error!", nil) - informativeText:NSLocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; } } } @@ -145,8 +145,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if (!servingOverHttps) { BOOL atsExceptionsExist = nil != [self.host objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; if (isMainBundle && !atsExceptionsExist) { - [self showAlertText:NSLocalizedString(@"Insecure feed URL is blocked in macOS 10.11", nil) - informativeText:[NSString stringWithFormat:NSLocalizedString(@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", nil), [feedURL absoluteString]]]; + [self showAlertText:SULocalizedString(@"Insecure feed URL is blocked in macOS 10.11", nil) + informativeText:[NSString stringWithFormat:SULocalizedString(@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", nil), [feedURL absoluteString]]]; } else if (!isMainBundle) { SULog(@"WARNING: Serving updates over HTTP may be blocked in macOS 10.11. Please change the feed URL (%@) to use HTTPS. For more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", feedURL); }