From 4c782a67ed99ae25bdcbfdde388a6f9946267a30 Mon Sep 17 00:00:00 2001 From: Zorg Date: Tue, 5 May 2015 20:22:02 -0400 Subject: [PATCH] Abort if code signed xattr exists anywhere Code signatures on non-mach-o files is not currently supported, but I'd like to implement this eventually. --- Sparkle/SUBinaryDeltaCreate.m | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Sparkle/SUBinaryDeltaCreate.m b/Sparkle/SUBinaryDeltaCreate.m index a477d674..bc802bdc 100644 --- a/Sparkle/SUBinaryDeltaCreate.m +++ b/Sparkle/SUBinaryDeltaCreate.m @@ -18,6 +18,7 @@ #include #include #include +#include #include extern int bsdiff(int argc, const char **argv); @@ -101,6 +102,38 @@ static bool aclExists(const FTSENT *ent) return false; } +static bool codeSignatureExtendedAttributeExists(const FTSENT *ent) +{ + const int options = XATTR_NOFOLLOW; + ssize_t listSize = listxattr(ent->fts_path, NULL, 0, options); + if (listSize == -1) { + return false; + } + + char *buffer = malloc((size_t)listSize); + assert(buffer != NULL); + + ssize_t sizeBack = listxattr(ent->fts_path, buffer, (size_t)listSize, options); + assert(sizeBack == listSize); + + size_t startCharacterIndex = 0; + for (size_t characterIndex = 0; characterIndex < (size_t)listSize; characterIndex++) { + if (buffer[characterIndex] == '\0') { + char *attribute = &buffer[startCharacterIndex]; + size_t length = characterIndex - startCharacterIndex; + if (strncmp("com.apple.cs.CodeDirectory", attribute, length) == 0 || + strncmp("com.apple.cs.CodeRequirements", attribute, length) == 0 || + strncmp("com.apple.cs.CodeSignature", attribute, length) == 0) { + return true; + } + startCharacterIndex = characterIndex + 1; + } + } + + free(buffer); + return false; +} + static NSString *absolutePath(NSString *path) { NSURL *url = [[NSURL alloc] initFileURLWithPath:path]; @@ -237,6 +270,11 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi fprintf(stderr, "\nDiffing ACLs are not supported. Detected ACL in before-tree on file %s\n", ent->fts_path); return 1; } + + if (codeSignatureExtendedAttributeExists(ent)) { + fprintf(stderr, "\nDiffing code signed extended attributes is not supported yet. Detected extended attribute in before-tree on file %s\n", ent->fts_path); + return 1; + } } fts_close(fts); @@ -295,6 +333,11 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi return 1; } + if (codeSignatureExtendedAttributeExists(ent)) { + fprintf(stderr, "\nDiffing code signed extended attributes is not supported yet. Detected extended attribute in after-tree on file %s\n", ent->fts_path); + return 1; + } + NSDictionary *oldInfo = originalTreeState[key]; if ([info isEqual:oldInfo]) {