From a962c8fa8fd8b0441c1f45f9029472052dfe551f Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 16 Jul 2016 00:09:42 -0400 Subject: [PATCH] Make sure Mach service names are shorter than 64 characters NSXPCConnection has this length restriction on 10.8 and possibly later versions of macOS --- Sparkle/Autoupdate/SUMessageTypes.m | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Sparkle/Autoupdate/SUMessageTypes.m b/Sparkle/Autoupdate/SUMessageTypes.m index 1e5628c7..7b3461b2 100644 --- a/Sparkle/Autoupdate/SUMessageTypes.m +++ b/Sparkle/Autoupdate/SUMessageTypes.m @@ -11,6 +11,16 @@ NSString *SUAppcastItemArchiveKey = @"SUAppcastItemArchive"; +// Tags added to the bundle identifier which is used as Mach service names +// These should be very short because length restrictions exist on earlier versions of macOS +#define SPARKLE_INSTALLER_TAG @"-spki" +#define SPARKLE_STATUS_TAG @"-spks" + +// macOS 10.8 at least can't handle service names that are 64 characters or longer +// This was fixed some point after 10.8, but I'm not sure if it was fixed in 10.9 or 10.10 or 10.11 +// If we knew when it was fixed, this could only be relevant to OS versions prior to that +#define MAX_SERVICE_NAME_LENGTH 63u + BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInstallerMessageType newMessageType) { BOOL legal; @@ -49,12 +59,21 @@ BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInst return legal; } +static NSString *SUServiceNameWithTag(NSString *tagName, NSString *bundleIdentifier) +{ + NSString *serviceName = [bundleIdentifier stringByAppendingString:tagName]; + NSUInteger length = MIN(serviceName.length, MAX_SERVICE_NAME_LENGTH); + // If the service name is too long, cut off the beginning rather than cutting off the end + // This should lead to a more unique name + return [serviceName substringFromIndex:serviceName.length - length]; +} + NSString *SUAutoUpdateServiceNameForBundleIdentifier(NSString *bundleIdentifier) { - return [NSString stringWithFormat:@"%@-spkinstll", bundleIdentifier]; + return SUServiceNameWithTag(SPARKLE_INSTALLER_TAG, bundleIdentifier); } NSString *SUStatusInfoServiceNameForBundleIdentifier(NSString *bundleIdentifier) { - return [NSString stringWithFormat:@"%@-spkstat", bundleIdentifier]; + return SUServiceNameWithTag(SPARKLE_STATUS_TAG, bundleIdentifier); }