From 48f18d000c651e517ea244bb61c2ba51a8d71e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Tue, 1 Mar 2016 00:37:35 +0000 Subject: [PATCH 01/17] Support XML namespace prefixes when parsing appcasts Fixes #771 --- Sparkle/SUAppcast.m | 48 +++++++++++++++++++-------------- Tests/Resources/testappcast.xml | 7 ++--- Tests/SUAppcastTest.swift | 3 ++- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index ac1c43bb..c953be04 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -19,23 +19,6 @@ @property (readonly, copy) NSDictionary *attributesAsDictionary; @end -@implementation NSXMLElement (SUAppcastExtensions) -- (NSDictionary *)attributesAsDictionary -{ - NSEnumerator *attributeEnum = [[self attributes] objectEnumerator]; - NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - - for (NSXMLNode *attribute in attributeEnum) { - NSString *attrName = [attribute name]; - if (!attrName) { - continue; - } - dictionary[attrName] = [attribute stringValue]; - } - return dictionary; -} -@end - @interface SUAppcast () @property (strong) void (^completionBlock)(NSError *); @property (copy) NSString *downloadFilename; @@ -115,6 +98,31 @@ } } +- (NSDictionary *)attributesOfNode:(NSXMLElement *)node +{ + NSEnumerator *attributeEnum = [[node attributes] objectEnumerator]; + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + + for (NSXMLNode *attribute in attributeEnum) { + NSString *attrName = [self sparkleNamespacedNameOfNode:attribute]; + if (!attrName) { + continue; + } + dictionary[attrName] = [attribute stringValue]; + } + return dictionary; +} + +-(NSString *)sparkleNamespacedNameOfNode:(NSXMLNode *)node { + // XML namespace prefix is semantically meaningless, so compare namespace URI + if ([[node URI] isEqualToString:@"http://www.andymatuschak.org/xml-namespaces/sparkle"]) { + NSString *localName = [node localName]; assert(localName); + return [@"sparkle:" stringByAppendingString:localName]; + } else { + return [node name]; // Backwards compatibility + } +} + -(NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp { if (errorp) { *errorp = nil; @@ -147,7 +155,7 @@ if ([[node children] count]) { node = [node childAtIndex:0]; while (nil != node) { - NSString *name = [node name]; + NSString *name = [self sparkleNamespacedNameOfNode:node]; if (name) { NSMutableArray *nodes = nodesDict[name]; if (nodes == nil) { @@ -164,7 +172,7 @@ node = [self bestNodeInNodes:nodesDict[name]]; if ([name isEqualToString:SURSSElementEnclosure]) { // enclosure is flattened as a separate dictionary for some reason - NSDictionary *encDict = [(NSXMLElement *)node attributesAsDictionary]; + NSDictionary *encDict = [self attributesOfNode:(NSXMLElement *)node]; dict[name] = encDict; } else if ([name isEqualToString:SURSSElementPubDate]) { @@ -182,7 +190,7 @@ NSEnumerator *childEnum = [[node children] objectEnumerator]; for (NSXMLNode *child in childEnum) { if ([[child name] isEqualToString:SURSSElementEnclosure]) { - [deltas addObject:[(NSXMLElement *)child attributesAsDictionary]]; + [deltas addObject:[self attributesOfNode:(NSXMLElement *)child]]; } } dict[name] = deltas; diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index 0023508e..cc1297b4 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -1,17 +1,18 @@ - + For unit test only Version 2.0 desc Sat, 26 Jul 2014 15:20:11 +0000 - + Version 3.0 Sat, 26 Jul 2014 15:20:12 +0000 - + https://sparkle-project.org/#works + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index 5f39f795..a211b46f 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -11,7 +11,7 @@ import Sparkle; class SUAppcastTest: XCTestCase { - func testExample() { + func testParseAppcast() { let appcast = SUAppcast(); let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testappcast", ofType: "xml")!; let testFileUrl = NSURL(fileURLWithPath: testFile); @@ -26,6 +26,7 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual("Version 2.0", items[1].title); XCTAssertEqual("desc", items[1].itemDescription); + XCTAssertEqual("https://sparkle-project.org/#works", items[0].releaseNotesURL!.absoluteString); } catch let err as NSError { NSLog("%@", err); XCTFail(err.localizedDescription); From c9fa1142c9843bf0919d01db417a0931c9be16ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Mon, 14 Mar 2016 12:22:35 +0000 Subject: [PATCH 02/17] Formatting/comments --- Sparkle/SUAppcast.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index c953be04..8fc8ad4f 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -115,8 +115,10 @@ -(NSString *)sparkleNamespacedNameOfNode:(NSXMLNode *)node { // XML namespace prefix is semantically meaningless, so compare namespace URI + // NS URI isn't used to fetch anything, and must match exactly, so we look for http:// not https:// if ([[node URI] isEqualToString:@"http://www.andymatuschak.org/xml-namespaces/sparkle"]) { - NSString *localName = [node localName]; assert(localName); + NSString *localName = [node localName]; + assert(localName); return [@"sparkle:" stringByAppendingString:localName]; } else { return [node name]; // Backwards compatibility From 71e15f4b1dd8f6aac39d0c9dbb720389767acb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Tue, 10 May 2016 13:32:27 +0100 Subject: [PATCH 03/17] Update changelog --- CHANGELOG | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index d730c9db..1af8a3e9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,24 @@ + +* A new icon! Thanks to 1024jp +* Show alert when an update is sent over insecure HTTP with no DSA key (Zorg) + - If you can't use HTTPS, you must at least sign updates with a DSA key. +* Clear update caches directory before downloading new update (Zorg) +* Check the bundle's parent directory for writability too (Zorg) +* Don't follow symbolic links for file operations (Zorg) +* Don't bring up an authorized dialog during cleanup (Zorg) +* Made Sparkle look for the highest compatible version regardless of timestamps (Zorg) +* Fixed compatibility with 10.7 + * Fixed crash on 10.7 - subscript operator not available (kleuter) + * Fixed warnings caused by -Wpartial-availability (Zorg) +* Fixed german l10n. (Sebastian Volland) +* Error code for download errors (Kornel Lesiński) +* Update last update check date when the update driver finishes (Zorg) +* Scale app icon up if needed in Software Update window (#763) (Nicholas Riley) +* Improved tests (Zorg) +* Don't register for termination notifications more than once. Fixes #757 (Zorg) +* Don't terminate the app if we're already terminating (Zorg) +* Removed SUEnableAutomaticChecksKeyOld and SUCheckAtStartup constants (Eitot) + # 1.14.0 (Mar 11, 2016) * Disable javascript by default and make it opt-in (Zorg) From e2c60be8059602c0c73bea0ce3d928539db7ae55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Thu, 12 May 2016 15:19:57 +0100 Subject: [PATCH 04/17] Reorganize checks for clarity --- Sparkle/SUUpdater.m | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 8a7b4bc8..29afa018 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -125,25 +125,31 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned]; NSURL *feedURL = [self feedURL]; BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"]; - if (!isMainBundle && !hasPublicDSAKey) { - [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."]; - } else if (isMainBundle && !(hasPublicDSAKey || 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 Sparkle's documentation for more information."]; - } else if (isMainBundle && !hasPublicDSAKey && !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 Sparkle's documentation for more information."]; + + 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."]; + } 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."]; + } 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."]; + } + } } #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 - BOOL atsExceptionsExist = nil != [self.host objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; - if (isMainBundle && !servingOverHttps && !atsExceptionsExist) { - [self showAlertText:@"Insecure feed URL is blocked in OS X 10.11" - informativeText:[NSString stringWithFormat:@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttp://sparkle-project.org/documentation/app-transport-security/", [feedURL absoluteString]]]; - } - if (!isMainBundle && !servingOverHttps) { - SULog(@"WARNING: Serving updates over HTTP may be blocked in OS X 10.11. Please change the feed URL (%@) to use HTTPS. For more information:\nhttp://sparkle-project.org/documentation/app-transport-security/", feedURL); + if (!servingOverHttps) { + BOOL atsExceptionsExist = nil != [self.host objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; + if (isMainBundle && !atsExceptionsExist) { + [self showAlertText:@"Insecure feed URL is blocked in OS X 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]]]; + } else if (!isMainBundle) { + SULog(@"WARNING: Serving updates over HTTP may be blocked in OS X 10.11. Please change the feed URL (%@) to use HTTPS. For more information:\nhttps://sparkle-project.org/documentation/app-transport-security/", feedURL); + } } #endif } From 0e2fe68399565db63ab4c411d1471abf1a8164ec Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 21:57:19 -0400 Subject: [PATCH 05/17] Don't hide warnings for bsdiff/bspatch --- Sparkle.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 18fbe574..2b5be7a0 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -33,7 +33,7 @@ 142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 142E0E0819A83AAC00E4312B /* SUBinaryDeltaTest.m */; }; 14652F7C19A9725300959E44 /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */; }; 14652F7D19A9726700959E44 /* SUBinaryDeltaApply.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E00FD68CC7005AE3F6 /* SUBinaryDeltaApply.m */; }; - 14652F7E19A9728A00959E44 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; }; + 14652F7E19A9728A00959E44 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; }; 14652F8019A9740F00959E44 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 14652F8219A9746000959E44 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; 14652F8419A978C200959E44 /* SUExport.h in Headers */ = {isa = PBXBuildFile; fileRef = 14652F8319A9759F00959E44 /* SUExport.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -81,9 +81,9 @@ 5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */; }; 5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */; }; 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */; }; - 5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; + 5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; }; 5D06E8EA0FD68CDB005AE3F6 /* SUBinaryDeltaTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */; }; - 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; }; + 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; }; 5D06E8EC0FD68CE4005AE3F6 /* SUBinaryDeltaApply.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E00FD68CC7005AE3F6 /* SUBinaryDeltaApply.m */; }; 5D06E8ED0FD68CE4005AE3F6 /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */; }; 5D06E8FD0FD68D6B005AE3F6 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; @@ -171,9 +171,9 @@ 720B16441C66433D006985FB /* UITests-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 720B16421C66433D006985FB /* UITests-Info.plist */; }; 720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; }; 7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; }; - 721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - 721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - 721CF1A91AD7644C00D9AC09 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; settings = {COMPILER_FLAGS = "-w"; }; }; + 721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; }; + 721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; }; + 721CF1A91AD7644C00D9AC09 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; }; 721CF1AA1AD7647000D9AC09 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; }; 721CF1AB1AD764EB00D9AC09 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; 7223E7631AD1AEFF008E3161 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; }; From c11c660f223c063ee4179f7e0b81aed2ff8e7446 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 9 Apr 2016 14:36:16 -0400 Subject: [PATCH 06/17] Fix warnings for bspatch --- Vendor/bsdiff/bspatch.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Vendor/bsdiff/bspatch.c b/Vendor/bsdiff/bspatch.c index ca7a72ab..4ba2e6cc 100644 --- a/Vendor/bsdiff/bspatch.c +++ b/Vendor/bsdiff/bspatch.c @@ -46,7 +46,7 @@ typedef struct { stream_t (*open)(FILE*); void (*close)(stream_t); - int (*read)(stream_t, void*, int); + off_t (*read)(stream_t, void*, off_t); } io_funcs_t; static stream_t BSDIFF40_open(FILE *f) @@ -64,10 +64,10 @@ static void BSDIFF40_close(stream_t s) BZ2_bzReadClose(&bzerr, (BZFILE*)s); } -static int BSDIFF40_read(stream_t s, void *buf, int len) +static off_t BSDIFF40_read(stream_t s, void *buf, off_t len) { int bzerr, lenread; - lenread = BZ2_bzRead(&bzerr, (BZFILE*)s, buf, len); + lenread = BZ2_bzRead(&bzerr, (BZFILE*)s, buf, (int)len); if (bzerr != BZ_OK && bzerr != BZ_STREAM_END) errx(1, "Corrupt patch\n"); return lenread; @@ -85,13 +85,13 @@ static stream_t BSDIFN40_open(FILE *f) return f; } -static void BSDIFN40_close(stream_t s) +static void BSDIFN40_close(stream_t __unused s) { } -static int BSDIFN40_read(stream_t s, void *buf, int len) +static off_t BSDIFN40_read(stream_t s, void *buf, off_t len) { - return fread(buf, 1, len, (FILE*)s); + return (off_t)fread(buf, 1, (size_t)len, (FILE*)s); } static io_funcs_t BSDIFN40_funcs = { @@ -204,11 +204,11 @@ int bspatch(int argc,const char * const argv[]) if(((fd=open(argv[1],O_RDONLY,0))<0) || ((oldsize=lseek(fd,0,SEEK_END))==-1) || - ((old=malloc(oldsize+1))==NULL) || + ((old=malloc((size_t)oldsize+1))==NULL) || (lseek(fd,0,SEEK_SET)!=0) || - (read(fd,old,oldsize)!=oldsize) || + (read(fd,old,(size_t)oldsize)!=oldsize) || (close(fd)==-1)) err(1,"%s",argv[1]); - if((new=malloc(newsize+1))==NULL) err(1,NULL); + if((new=malloc((size_t)newsize+1))==NULL) err(1,NULL); oldpos=0;newpos=0; while(newpos Date: Mon, 16 May 2016 10:57:42 -0400 Subject: [PATCH 07/17] Use FILE* (fopen/fread/etc) functions for bsdiff.c This way we don't have to handle EINTR --- Vendor/bsdiff/bsdiff.c | 76 +++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/Vendor/bsdiff/bsdiff.c b/Vendor/bsdiff/bsdiff.c index 9d55aded..32e5c1e0 100644 --- a/Vendor/bsdiff/bsdiff.c +++ b/Vendor/bsdiff/bsdiff.c @@ -115,11 +115,55 @@ static void offtout(off_t x, u_char *buf) buf[7] |= 0x80; } +static u_char *readfile(const char *filename, off_t *outSize) +{ + FILE *file = fopen(filename, "r"); + if (file == NULL) { + return NULL; + } + + if (fseek(file, 0L, SEEK_END) != 0) { + fclose(file); + return NULL; + } + + off_t size = ftell(file); + if (size == -1) { + fclose(file); + return NULL; + } + + if (outSize != NULL) { + *outSize = size; + } + + /* Allocate size + 1 bytes instead of newsize bytes to ensure + that we never try to malloc(0) and get a NULL pointer */ + u_char *buffer = malloc(size + 1); + if (buffer == NULL) { + fclose(file); + return NULL; + } + + if (fseek(file, 0L, SEEK_SET) != 0) { + fclose(file); + return NULL; + } + + if (fread(buffer, 1, size, file) < size) { + fclose(file); + return NULL; + } + + fclose(file); + + return buffer; +} + int bsdiff(int argc, char *argv[]); // Added by AMM: suppresses a warning about the following not having a prototype. int bsdiff(int argc, char *argv[]) { - int fd; u_char *old,*new; /* contents of old, new files */ off_t oldsize, newsize; /* length of old, new files */ off_t *I,*V; /* arrays used for suffix sort; I is ordering */ @@ -142,15 +186,11 @@ int bsdiff(int argc, char *argv[]) if (argc != 4) errx(1,"usage: %s oldfile newfile patchfile\n", argv[0]); - /* Allocate oldsize + 1 bytes instead of oldsize bytes to ensure - that we never try to malloc(0) and get a NULL pointer */ - if (((fd = open(argv[1], O_RDONLY, 0)) < 0) || - ((oldsize = lseek(fd, 0, SEEK_END)) == -1) || - ((old = malloc(oldsize + 1)) == NULL) || - (lseek(fd, 0, SEEK_SET) != 0) || - (read(fd, old, oldsize) != oldsize) || - (close(fd) == -1)) - err(1,"%s", argv[1]); + old = readfile(argv[1], &oldsize); + if (old == NULL) { + warn("old file error: %s", argv[1]); + return -1; + } if (((I = malloc((oldsize + 1) * sizeof(off_t))) == NULL) || ((V = malloc((oldsize + 1) * sizeof(off_t))) == NULL)) @@ -160,16 +200,12 @@ int bsdiff(int argc, char *argv[]) I[0] = oldsize; sais(old, I+1, oldsize); free(V); - - /* Allocate newsize + 1 bytes instead of newsize bytes to ensure - that we never try to malloc(0) and get a NULL pointer */ - if (((fd = open(argv[2], O_RDONLY, 0)) < 0) || - ((newsize = lseek(fd, 0, SEEK_END)) == -1) || - ((new = malloc(newsize + 1)) == NULL) || - (lseek(fd, 0, SEEK_SET) != 0) || - (read(fd, new, newsize) != newsize) || - (close(fd) == -1)) - err(1,"%s", argv[2]); + + new = readfile(argv[2], &newsize); + if (new == NULL) { + warn("new file error: %s", argv[2]); + return -1; + } if (((db = malloc(newsize + 1)) == NULL) || ((eb = malloc(newsize + 1)) == NULL)) From 914bf9e33317959d45d493068a662ee274d49910 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 18:21:52 -0400 Subject: [PATCH 08/17] Use FILE* functions in bspatch.c --- Sparkle.xcodeproj/project.pbxproj | 12 +++++++ Vendor/bsdiff/bscommon.c | 56 +++++++++++++++++++++++++++++++ Vendor/bsdiff/bscommon.h | 16 +++++++++ Vendor/bsdiff/bsdiff.c | 47 ++------------------------ Vendor/bsdiff/bspatch.c | 37 ++++++++++++++------ 5 files changed, 113 insertions(+), 55 deletions(-) create mode 100644 Vendor/bsdiff/bscommon.c create mode 100644 Vendor/bsdiff/bscommon.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 2b5be7a0..5d2ed17f 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -177,6 +177,10 @@ 721CF1AA1AD7647000D9AC09 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; }; 721CF1AB1AD764EB00D9AC09 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; 7223E7631AD1AEFF008E3161 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; }; + 723B252D1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; }; + 723B252E1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; }; + 723B252F1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; }; + 723B25301CEAB3A600909873 /* bscommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 723B252C1CEAB3A600909873 /* bscommon.h */; }; 7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */; }; 726F2CDE1BC9BE5B001971A4 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; 726F2CE51BC9C33D001971A4 /* SUOperatingSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 726F2CE31BC9C33D001971A4 /* SUOperatingSystem.h */; }; @@ -628,6 +632,8 @@ 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = ""; }; 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; + 723B252B1CEAB3A600909873 /* bscommon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bscommon.c; sourceTree = ""; }; + 723B252C1CEAB3A600909873 /* bscommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bscommon.h; sourceTree = ""; }; 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaCreate.m; sourceTree = ""; }; 7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaCreate.h; sourceTree = ""; }; 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -840,6 +846,8 @@ 14732BB61960ECE800593899 /* bsdiff */ = { isa = PBXGroup; children = ( + 723B252B1CEAB3A600909873 /* bscommon.c */, + 723B252C1CEAB3A600909873 /* bscommon.h */, 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */, 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */, 611142E810FB1BE5009810AA /* bspatch.h */, @@ -1183,6 +1191,7 @@ 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, 767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */, 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, + 723B25301CEAB3A600909873 /* bscommon.h in Headers */, 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */, 55C14F06136EF6DB00649790 /* SULog.h in Headers */, 726F2CE51BC9C33D001971A4 /* SUOperatingSystem.h in Headers */, @@ -1616,6 +1625,7 @@ 5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */, 14652F7E19A9728A00959E44 /* bspatch.c in Sources */, 7223E7631AD1AEFF008E3161 /* sais.c in Sources */, + 723B252F1CEAB3A600909873 /* bscommon.c in Sources */, 14652F7D19A9726700959E44 /* SUBinaryDeltaApply.m in Sources */, 14652F7C19A9725300959E44 /* SUBinaryDeltaCommon.m in Sources */, 7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */, @@ -1635,6 +1645,7 @@ 721CF1A91AD7644C00D9AC09 /* sais.c in Sources */, 5A4094481C74EA5200983BE0 /* SUAppcastTest.swift in Sources */, 72D4DAA11AD7632900B211E2 /* SUBinaryDeltaCreate.m in Sources */, + 723B252E1CEAB3A600909873 /* bscommon.c in Sources */, 142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */, F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */, 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */, @@ -1692,6 +1703,7 @@ 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */, 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */, 55C14F07136EF6DB00649790 /* SULog.m in Sources */, + 723B252D1CEAB3A600909873 /* bscommon.c in Sources */, 726F2CE61BC9C33D001971A4 /* SUOperatingSystem.m in Sources */, 618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */, 61D85D6D0E10B2ED00F9B4A9 /* SUPipedUnarchiver.m in Sources */, diff --git a/Vendor/bsdiff/bscommon.c b/Vendor/bsdiff/bscommon.c new file mode 100644 index 00000000..c1bd7016 --- /dev/null +++ b/Vendor/bsdiff/bscommon.c @@ -0,0 +1,56 @@ +/* + * bscommon.c + * Sparkle + * + * Created by Mayur Pawashe on 5/16/16. + */ + +#include "bscommon.h" +#include + +u_char *readfile(const char *filename, off_t *outSize) +{ + FILE *file = fopen(filename, "r"); + if (file == NULL) { + return NULL; + } + + if (fseek(file, 0L, SEEK_END) != 0) { + fclose(file); + return NULL; + } + + long offset = ftell(file); + if (offset == -1) { + fclose(file); + return NULL; + } + + size_t size = (size_t)offset; + + if (outSize != NULL) { + *outSize = (off_t)size; + } + + /* Allocate size + 1 bytes instead of newsize bytes to ensure + that we never try to malloc(0) and get a NULL pointer */ + u_char *buffer = malloc(size + 1); + if (buffer == NULL) { + fclose(file); + return NULL; + } + + if (fseek(file, 0L, SEEK_SET) != 0) { + fclose(file); + return NULL; + } + + if (fread(buffer, 1, size, file) < size) { + fclose(file); + return NULL; + } + + fclose(file); + + return buffer; +} diff --git a/Vendor/bsdiff/bscommon.h b/Vendor/bsdiff/bscommon.h new file mode 100644 index 00000000..d90273fc --- /dev/null +++ b/Vendor/bsdiff/bscommon.h @@ -0,0 +1,16 @@ +/* + * bscommon.h + * Sparkle + * + * Created by Mayur Pawashe on 5/16/16. + */ + +#ifndef BS_COMMON_H +#define BS_COMMON_H + +#include +#include + +u_char *readfile(const char *filename, off_t *outSize); + +#endif diff --git a/Vendor/bsdiff/bsdiff.c b/Vendor/bsdiff/bsdiff.c index 32e5c1e0..8bad3451 100644 --- a/Vendor/bsdiff/bsdiff.c +++ b/Vendor/bsdiff/bsdiff.c @@ -38,6 +38,8 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c, v 1.1 2005/08/06 01:59:0 #include #include +#include "bscommon.h" + #define MIN(x, y) (((x)<(y)) ? (x) : (y)) /* matchlen(old, oldsize, new, newsize) @@ -115,51 +117,6 @@ static void offtout(off_t x, u_char *buf) buf[7] |= 0x80; } -static u_char *readfile(const char *filename, off_t *outSize) -{ - FILE *file = fopen(filename, "r"); - if (file == NULL) { - return NULL; - } - - if (fseek(file, 0L, SEEK_END) != 0) { - fclose(file); - return NULL; - } - - off_t size = ftell(file); - if (size == -1) { - fclose(file); - return NULL; - } - - if (outSize != NULL) { - *outSize = size; - } - - /* Allocate size + 1 bytes instead of newsize bytes to ensure - that we never try to malloc(0) and get a NULL pointer */ - u_char *buffer = malloc(size + 1); - if (buffer == NULL) { - fclose(file); - return NULL; - } - - if (fseek(file, 0L, SEEK_SET) != 0) { - fclose(file); - return NULL; - } - - if (fread(buffer, 1, size, file) < size) { - fclose(file); - return NULL; - } - - fclose(file); - - return buffer; -} - int bsdiff(int argc, char *argv[]); // Added by AMM: suppresses a warning about the following not having a prototype. int bsdiff(int argc, char *argv[]) diff --git a/Vendor/bsdiff/bspatch.c b/Vendor/bsdiff/bspatch.c index 4ba2e6cc..bfde7208 100644 --- a/Vendor/bsdiff/bspatch.c +++ b/Vendor/bsdiff/bspatch.c @@ -37,6 +37,8 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59: #include #include +#include "bscommon.h" + /* Compatibility layer for reading either the old BSDIFF40 or the new BSDIFN40 patch formats: */ @@ -127,7 +129,6 @@ int bspatch(int argc,const char * const argv[]) { FILE * f, * cpf, * dpf, * epf; stream_t cstream, dstream, estream; - int fd; ssize_t oldsize,newsize; ssize_t bzctrllen,bzdatalen; u_char header[32],buf[8]; @@ -202,12 +203,15 @@ int bspatch(int argc,const char * const argv[]) (long long)(32 + bzctrllen + bzdatalen)); estream = io->open(epf); - if(((fd=open(argv[1],O_RDONLY,0))<0) || - ((oldsize=lseek(fd,0,SEEK_END))==-1) || - ((old=malloc((size_t)oldsize+1))==NULL) || - (lseek(fd,0,SEEK_SET)!=0) || - (read(fd,old,(size_t)oldsize)!=oldsize) || - (close(fd)==-1)) err(1,"%s",argv[1]); + off_t size = 0; + old = readfile(argv[1], &size); + if (old == NULL) { + warn("old file: %s", argv[1]); + return -1; + } + + oldsize = size; + if((new=malloc((size_t)newsize+1))==NULL) err(1,NULL); oldpos=0;newpos=0; @@ -260,9 +264,22 @@ int bspatch(int argc,const char * const argv[]) err(1, "fclose(%s)", argv[3]); /* Write the new file */ - if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || - (write(fd,new,(size_t)newsize)!=newsize) || (close(fd)==-1)) - err(1,"%s",argv[2]); + FILE *writeFile = fopen(argv[2], "w"); + if (writeFile == NULL) { + warn("failed to write new file: %s", argv[2]); + return -1; + } + + if (fwrite(new, 1, (size_t)newsize, writeFile) < (size_t)newsize) { + warn("failed to write to new file: %s", argv[2]); + fclose(writeFile); + return -1; + } + + if (fclose(writeFile) != 0) { + warn("failed to close new file: %s", argv[2]); + return -1; + } free(new); free(old); From 48eb25fbf3567e2faccce3e21d1cf4264a17092c Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 19:01:09 -0400 Subject: [PATCH 09/17] Don't exit the program on failure for bspatch.c We call warn type functions instead of err ones now and do some cleanup --- Vendor/bsdiff/bspatch.c | 244 +++++++++++++++++++++++++++++----------- 1 file changed, 177 insertions(+), 67 deletions(-) diff --git a/Vendor/bsdiff/bspatch.c b/Vendor/bsdiff/bspatch.c index bfde7208..56d39dcb 100644 --- a/Vendor/bsdiff/bspatch.c +++ b/Vendor/bsdiff/bspatch.c @@ -53,10 +53,11 @@ typedef struct static stream_t BSDIFF40_open(FILE *f) { - int bzerr; - BZFILE *s; - if ((s = BZ2_bzReadOpen(&bzerr, f, 0, 0, NULL, 0)) == NULL) - errx(1, "BZ2_bzReadOpen, bz2err = %d", bzerr); + int bzerr = 0; + BZFILE *s = NULL; + if ((s = BZ2_bzReadOpen(&bzerr, f, 0, 0, NULL, 0)) == NULL) { + warnx("BZ2_bzReadOpen, bz2err = %d", bzerr); + } return s; } @@ -68,10 +69,12 @@ static void BSDIFF40_close(stream_t s) static off_t BSDIFF40_read(stream_t s, void *buf, off_t len) { - int bzerr, lenread; + int bzerr = 0, lenread = 0; lenread = BZ2_bzRead(&bzerr, (BZFILE*)s, buf, (int)len); - if (bzerr != BZ_OK && bzerr != BZ_STREAM_END) - errx(1, "Corrupt patch\n"); + if (bzerr != BZ_OK && bzerr != BZ_STREAM_END) { + warnx("Corrupt patch\n"); + lenread = -1; + } return lenread; } @@ -127,23 +130,29 @@ static off_t offtin(u_char *buf) int bspatch(int argc,const char * const argv[]) { - FILE * f, * cpf, * dpf, * epf; - stream_t cstream, dstream, estream; - ssize_t oldsize,newsize; - ssize_t bzctrllen,bzdatalen; - u_char header[32],buf[8]; - u_char *old, *new; - off_t oldpos,newpos; - off_t ctrl[3]; - off_t lenread; - off_t i; - io_funcs_t * io; + FILE * f = NULL, * cpf = NULL, * dpf = NULL, * epf = NULL; + stream_t cstream = NULL, dstream = NULL, estream = NULL; + ssize_t oldsize = 0,newsize = 0; + ssize_t bzctrllen = 0,bzdatalen = 0; + u_char header[32] = {0},buf[8] = {0}; + u_char *old = NULL, *new = NULL; + off_t oldpos = 0,newpos = 0; + off_t ctrl[3] = {0}; + off_t lenread = 0; + off_t i = 0; + io_funcs_t * io = NULL; + int exitstatus = -1; - if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); + if(argc!=4) { + warnx("usage: %s oldfile newfile patchfile\n",argv[0]); + goto cleanup; + } /* Open patch file */ - if ((f = fopen(argv[3], "r")) == NULL) - err(1, "fopen(%s)", argv[3]); + if ((f = fopen(argv[3], "r")) == NULL) { + warn("fopen(%s)", argv[3]); + goto cleanup; + } /* File format: @@ -161,9 +170,12 @@ int bspatch(int argc,const char * const argv[]) /* Read header */ if (fread(header, 1, 32, f) < 32) { - if (feof(f)) - errx(1, "Corrupt patch\n"); - err(1, "fread(%s)", argv[3]); + if (feof(f)) { + warnx("Corrupt patch\n"); + } else { + warn("fread(%s)", argv[3]); + } + goto cleanup; } /* Check for appropriate magic */ @@ -171,67 +183,108 @@ int bspatch(int argc,const char * const argv[]) io = &BSDIFF40_funcs; else if (memcmp(header, "BSDIFN40", 8) == 0) io = &BSDIFN40_funcs; - else - errx(1, "Corrupt patch\n"); + else { + warnx("Corrupt patch\n"); + goto cleanup; + } /* Read lengths from header */ bzctrllen=offtin(header+8); bzdatalen=offtin(header+16); newsize=offtin(header+24); - if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) - errx(1,"Corrupt patch\n"); + if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) { + warnx("Corrupt patch\n"); + goto cleanup; + } /* Close patch file and re-open it via libbzip2 at the right places */ - if (fclose(f)) - err(1, "fclose(%s)", argv[3]); - if ((cpf = fopen(argv[3], "r")) == NULL) - err(1, "fopen(%s)", argv[3]); - if (fseeko(cpf, 32, SEEK_SET)) - err(1, "fseeko(%s, %lld)", argv[3], + if (fclose(f)) { + warn("fclose(%s)", argv[3]); + f = NULL; + goto cleanup; + } + f = NULL; + + if ((cpf = fopen(argv[3], "r")) == NULL) { + warn("fopen(%s)", argv[3]); + goto cleanup; + } + if (fseeko(cpf, 32, SEEK_SET)) { + warn("fseeko(%s, %lld)", argv[3], (long long)32); + goto cleanup; + } cstream = io->open(cpf); - if ((dpf = fopen(argv[3], "r")) == NULL) - err(1, "fopen(%s)", argv[3]); - if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) - err(1, "fseeko(%s, %lld)", argv[3], + if (cstream == NULL) { + warn("cstream open"); + goto cleanup; + } + if ((dpf = fopen(argv[3], "r")) == NULL) { + warn("fopen(%s)", argv[3]); + goto cleanup; + } + if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) { + warn("fseeko(%s, %lld)", argv[3], (long long)(32 + bzctrllen)); + goto cleanup; + } dstream = io->open(dpf); - if ((epf = fopen(argv[3], "r")) == NULL) - err(1, "fopen(%s)", argv[3]); - if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) - err(1, "fseeko(%s, %lld)", argv[3], + if (dstream == NULL) { + warn("dstream open"); + goto cleanup; + } + if ((epf = fopen(argv[3], "r")) == NULL) { + warn("fopen(%s)", argv[3]); + goto cleanup; + } + if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) { + warn("fseeko(%s, %lld)", argv[3], (long long)(32 + bzctrllen + bzdatalen)); + goto cleanup; + } estream = io->open(epf); - + if (estream == NULL) { + warn("estream open"); + goto cleanup; + } off_t size = 0; old = readfile(argv[1], &size); if (old == NULL) { warn("old file: %s", argv[1]); - return -1; + goto cleanup; } oldsize = size; - if((new=malloc((size_t)newsize+1))==NULL) err(1,NULL); + if((new=malloc((size_t)newsize+1))==NULL) { + warn("Failed to allocate memory for new"); + goto cleanup; + } oldpos=0;newpos=0; while(newposread(cstream, buf, 8); - if (lenread < 8) - errx(1, "Corrupt patch\n"); + if (lenread < 8) { + warnx("Corrupt patch\n"); + goto cleanup; + } ctrl[i]=offtin(buf); }; /* Sanity-check */ - if(newpos+ctrl[0]>newsize) - errx(1,"Corrupt patch\n"); + if(newpos+ctrl[0]>newsize) { + warnx("Corrupt patch\n"); + goto cleanup; + } /* Read diff string */ lenread = io->read(dstream, new + newpos, ctrl[0]); - if (lenread < ctrl[0]) - errx(1, "Corrupt patch\n"); + if (lenread < 0 || lenread < ctrl[0]) { + warnx("Corrupt patch\n"); + goto cleanup; + } /* Add old data to diff string */ for(i=0;inewsize) - errx(1,"Corrupt patch\n"); + if(newpos+ctrl[1]>newsize) { + warnx("Corrupt patch\n"); + goto cleanup; + } /* Read extra string */ lenread = io->read(estream, new + newpos, ctrl[1]); - if (lenread < ctrl[1]) - errx(1, "Corrupt patch\n"); + if (lenread < 0 || lenread < ctrl[1]) { + warnx("Corrupt patch\n"); + goto cleanup; + } /* Adjust pointers */ newpos+=ctrl[1]; @@ -258,31 +315,84 @@ int bspatch(int argc,const char * const argv[]) /* Clean up the bzip2 reads */ io->close(cstream); + cstream = NULL; io->close(dstream); + dstream = NULL; io->close(estream); - if (fclose(cpf) || fclose(dpf) || fclose(epf)) - err(1, "fclose(%s)", argv[3]); + estream = NULL; + + if (fclose(cpf) != 0) { + warn("fclose cpf(%s)", argv[3]); + cpf = NULL; + goto cleanup; + } + cpf = NULL; + + if (fclose(dpf) != 0) { + warn("fclose dpf(%s)", argv[3]); + dpf = NULL; + goto cleanup; + } + dpf = NULL; + + if (fclose(epf) != 0) { + warn("fclose epf(%s)", argv[3]); + epf = NULL; + goto cleanup; + } + epf = NULL; /* Write the new file */ - FILE *writeFile = fopen(argv[2], "w"); - if (writeFile == NULL) { + f = fopen(argv[2], "w"); + if (f == NULL) { warn("failed to write new file: %s", argv[2]); - return -1; + goto cleanup; } - if (fwrite(new, 1, (size_t)newsize, writeFile) < (size_t)newsize) { + if (fwrite(new, 1, (size_t)newsize, f) < (size_t)newsize) { warn("failed to write to new file: %s", argv[2]); - fclose(writeFile); - return -1; + goto cleanup; } - if (fclose(writeFile) != 0) { + if (fclose(f) != 0) { warn("failed to close new file: %s", argv[2]); - return -1; + f = NULL; + goto cleanup; } - + f = NULL; + + exitstatus = 0; +cleanup: free(new); free(old); + + if (f != NULL) { + fclose(f); + } + + if (estream != NULL) { + io->close(estream); + } + + if (epf != NULL) { + fclose(epf); + } + + if (dstream != NULL) { + io->close(dstream); + } + + if (dpf != NULL) { + fclose(dpf); + } + + if (cstream != NULL) { + io->close(cstream); + } + + if (cpf != NULL) { + fclose(cpf); + } - return 0; + return exitstatus; } From 07ac154e2e300902ad5b173e10a28394b51d02e9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 19:15:57 -0400 Subject: [PATCH 10/17] Don't exit the program on failure for bsdiff.c --- Vendor/bsdiff/bsdiff.c | 142 ++++++++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 50 deletions(-) diff --git a/Vendor/bsdiff/bsdiff.c b/Vendor/bsdiff/bsdiff.c index 8bad3451..6660500f 100644 --- a/Vendor/bsdiff/bsdiff.c +++ b/Vendor/bsdiff/bsdiff.c @@ -121,58 +121,68 @@ int bsdiff(int argc, char *argv[]); // Added by AMM: suppresses a warning about int bsdiff(int argc, char *argv[]) { - u_char *old,*new; /* contents of old, new files */ - off_t oldsize, newsize; /* length of old, new files */ - off_t *I,*V; /* arrays used for suffix sort; I is ordering */ - off_t scan; /* position of current match in old file */ + u_char *old = NULL,*new = NULL; /* contents of old, new files */ + off_t oldsize = 0, newsize = 0; /* length of old, new files */ + off_t *I = NULL,*V = NULL; /* arrays used for suffix sort; I is ordering */ + off_t scan = 0; /* position of current match in old file */ off_t pos = 0; /* position of current match in new file */ - off_t len; /* length of current match */ - off_t lastscan; /* position of previous match in old file */ - off_t lastpos; /* position of previous match in new file */ - off_t lastoffset; /* lastpos - lastscan */ - off_t oldscore, scsc; /* temp variables in match search */ - off_t s, Sf, lenf, Sb, lenb; /* temp vars in match extension */ - off_t overlap, Ss, lens; - off_t i; - off_t dblen, eblen; /* length of diff, extra sections */ - u_char *db,*eb; /* contents of diff, extra sections */ - u_char buf[8]; - u_char header[32]; - FILE * pf; + off_t len = 0; /* length of current match */ + off_t lastscan = 0; /* position of previous match in old file */ + off_t lastpos = 0; /* position of previous match in new file */ + off_t lastoffset = 0; /* lastpos - lastscan */ + off_t oldscore = 0, scsc = 0; /* temp variables in match search */ + off_t s = 0, Sf = 0, lenf = 0, Sb = 0, lenb = 0; /* temp vars in match extension */ + off_t overlap = 0, Ss = 0, lens = 0; + off_t i = 0; + off_t dblen = 0, eblen = 0; /* length of diff, extra sections */ + u_char *db = NULL,*eb = NULL; /* contents of diff, extra sections */ + u_char buf[8] = {0}; + u_char header[32] = {0}; + FILE * pf = NULL; + int exitstatus = -1; - if (argc != 4) - errx(1,"usage: %s oldfile newfile patchfile\n", argv[0]); + if (argc != 4) { + warnx("usage: %s oldfile newfile patchfile\n", argv[0]); + goto cleanup; + } old = readfile(argv[1], &oldsize); if (old == NULL) { warn("old file error: %s", argv[1]); - return -1; + goto cleanup; } if (((I = malloc((oldsize + 1) * sizeof(off_t))) == NULL) || - ((V = malloc((oldsize + 1) * sizeof(off_t))) == NULL)) - err(1, NULL); + ((V = malloc((oldsize + 1) * sizeof(off_t))) == NULL)) { + warn("Failed to allocate memory for I or V"); + goto cleanup; + } /* Do a suffix sort on the old file. */ I[0] = oldsize; sais(old, I+1, oldsize); free(V); + V = NULL; new = readfile(argv[2], &newsize); if (new == NULL) { warn("new file error: %s", argv[2]); - return -1; + goto cleanup; } if (((db = malloc(newsize + 1)) == NULL) || - ((eb = malloc(newsize + 1)) == NULL)) - err(1, NULL); + ((eb = malloc(newsize + 1)) == NULL)) { + warn("Failed to allocate memory for db or eb"); + goto cleanup; + } dblen = 0; eblen = 0; /* Create the patch file */ - if ((pf = fopen(argv[3], "w")) == NULL) - err(1, "%s", argv[3]); + if ((pf = fopen(argv[3], "w")) == NULL) { + warn("%s", argv[3]); + goto cleanup; + } /* Header is 0 8 "BSDIFN40" @@ -188,8 +198,10 @@ int bsdiff(int argc, char *argv[]) offtout(0, header + 8); offtout(0, header + 16); offtout(newsize, header + 24); - if (fwrite(header, 32, 1, pf) != 1) - err(1, "fwrite(%s)", argv[3]); + if (fwrite(header, 32, 1, pf) != 1) { + warn("fwrite(%s)", argv[3]); + goto cleanup; + } /* Compute the differences, writing ctrl as we go */ scan = 0; @@ -305,16 +317,22 @@ int bsdiff(int argc, char *argv[]) * diff, in the old file */ offtout(lenf, buf); - if (fwrite(buf, 8, 1, pf) != 1) - errx(1, "fwrite"); + if (fwrite(buf, 8, 1, pf) != 1) { + warnx("fwrite"); + goto cleanup; + } offtout((scan - lenb) - (lastscan + lenf), buf); - if (fwrite(buf, 8, 1, pf) != 1) - err(1, "fwrite"); + if (fwrite(buf, 8, 1, pf) != 1) { + warn("fwrite"); + goto cleanup; + } offtout((pos - lenb) - (lastpos + lenf), buf); - if (fwrite(buf, 8, 1, pf) != 1) - err(1, "fwrite"); + if (fwrite(buf, 8, 1, pf) != 1) { + warn("fwrite"); + goto cleanup; + } /* Update the variables describing the last match. Note that * 'lastscan' is set to the start of the current match _after_ the @@ -327,37 +345,61 @@ int bsdiff(int argc, char *argv[]) } /* Compute size of compressed ctrl data */ - if ((len = ftello(pf)) == -1) - err(1, "ftello"); + if ((len = ftello(pf)) == -1) { + warn("ftello"); + goto cleanup; + } offtout(len - 32, header + 8); /* Write diff data */ - if (dblen && fwrite(db, dblen, 1, pf) != 1) - err(1, "fwrite"); + if (dblen && fwrite(db, dblen, 1, pf) != 1) { + warn("fwrite"); + goto cleanup; + } /* Compute size of compressed diff data */ - if ((newsize = ftello(pf)) == -1) - err(1, "ftello"); + if ((newsize = ftello(pf)) == -1) { + warn("ftello"); + goto cleanup; + } offtout(newsize - len, header + 16); /* Write extra data */ - if (eblen && fwrite(eb, eblen, 1, pf) != 1) - err(1, "fwrite"); + if (eblen && fwrite(eb, eblen, 1, pf) != 1) { + warn("fwrite"); + goto cleanup; + } /* Seek to the beginning, write the header, and close the file */ - if (fseeko(pf, 0, SEEK_SET)) - err(1, "fseeko"); - if (fwrite(header, 32, 1, pf) != 1) - err(1, "fwrite(%s)", argv[3]); - if (fclose(pf)) - err(1, "fclose"); + if (fseeko(pf, 0, SEEK_SET)) { + warn("fseeko"); + goto cleanup; + } + if (fwrite(header, 32, 1, pf) != 1) { + warn("fwrite(%s)", argv[3]); + goto cleanup; + } + if (fclose(pf)) { + warn("fclose"); + pf = NULL; + goto cleanup; + } + pf = NULL; + + exitstatus = 0; +cleanup: + if (pf != NULL) { + fclose(pf); + } + /* Free the memory we used */ free(db); free(eb); free(I); + free(V); free(old); free(new); - return 0; + return exitstatus; } From f990f5fcfc022392849a2821dfaa54c4d95f2d21 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 19:22:34 -0400 Subject: [PATCH 11/17] Don't forget to free the buffer on failure --- Vendor/bsdiff/bscommon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Vendor/bsdiff/bscommon.c b/Vendor/bsdiff/bscommon.c index c1bd7016..fe09cecc 100644 --- a/Vendor/bsdiff/bscommon.c +++ b/Vendor/bsdiff/bscommon.c @@ -42,11 +42,13 @@ u_char *readfile(const char *filename, off_t *outSize) if (fseek(file, 0L, SEEK_SET) != 0) { fclose(file); + free(buffer); return NULL; } if (fread(buffer, 1, size, file) < size) { fclose(file); + free(buffer); return NULL; } From d71fe4a17d5917de53a9a8888fe6f103f79f7696 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 19:25:39 -0400 Subject: [PATCH 12/17] Improve error handling on readfile() --- Vendor/bsdiff/bscommon.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Vendor/bsdiff/bscommon.c b/Vendor/bsdiff/bscommon.c index fe09cecc..f492a1d6 100644 --- a/Vendor/bsdiff/bscommon.c +++ b/Vendor/bsdiff/bscommon.c @@ -10,20 +10,21 @@ u_char *readfile(const char *filename, off_t *outSize) { + int success = -1; + u_char *buffer = NULL; + FILE *file = fopen(filename, "r"); if (file == NULL) { - return NULL; + goto cleanup; } if (fseek(file, 0L, SEEK_END) != 0) { - fclose(file); - return NULL; + goto cleanup; } long offset = ftell(file); if (offset == -1) { - fclose(file); - return NULL; + goto cleanup; } size_t size = (size_t)offset; @@ -34,25 +35,28 @@ u_char *readfile(const char *filename, off_t *outSize) /* Allocate size + 1 bytes instead of newsize bytes to ensure that we never try to malloc(0) and get a NULL pointer */ - u_char *buffer = malloc(size + 1); + buffer = malloc(size + 1); if (buffer == NULL) { - fclose(file); - return NULL; + goto cleanup; } if (fseek(file, 0L, SEEK_SET) != 0) { - fclose(file); - free(buffer); - return NULL; + goto cleanup; } if (fread(buffer, 1, size, file) < size) { - fclose(file); - free(buffer); - return NULL; + goto cleanup; } - fclose(file); + success = 0; +cleanup: + if (success == -1) { + free(buffer); + buffer = NULL; + } + if (file != NULL) { + fclose(file); + } return buffer; } From e485baf8b8bc9e4b915202bd73fdb1145af71923 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 22:20:35 -0400 Subject: [PATCH 13/17] Fix warnings for bsdiff.c --- Vendor/bsdiff/bsdiff.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Vendor/bsdiff/bsdiff.c b/Vendor/bsdiff/bsdiff.c index 6660500f..8dfb3c20 100644 --- a/Vendor/bsdiff/bsdiff.c +++ b/Vendor/bsdiff/bsdiff.c @@ -84,7 +84,7 @@ static off_t search(off_t *I, u_char *old, off_t oldsize, } x = st + (en - st)/2; - if (memcmp(old + I[x], new, MIN(oldsize - I[x], newsize)) < 0) { + if (memcmp(old + I[x], new, (size_t)(MIN(oldsize - I[x], newsize))) < 0) { return search(I, old, oldsize, new, newsize, x, en, pos); } else { return search(I, old, oldsize, new, newsize, st, x, pos); @@ -103,15 +103,15 @@ static void offtout(off_t x, u_char *buf) else y = x; - buf[0] = y % 256; + buf[0] = (u_char)(y % 256); y -= buf[0]; - y = y/256; buf[1] = y%256; y -= buf[1]; - y = y/256; buf[2] = y%256; y -= buf[2]; - y = y/256; buf[3] = y%256; y -= buf[3]; - y = y/256; buf[4] = y%256; y -= buf[4]; - y = y/256; buf[5] = y%256; y -= buf[5]; - y = y/256; buf[6] = y%256; y -= buf[6]; - y = y/256; buf[7] = y%256; + y = y/256; buf[1] = (u_char)(y%256); y -= buf[1]; + y = y/256; buf[2] = (u_char)(y%256); y -= buf[2]; + y = y/256; buf[3] = (u_char)(y%256); y -= buf[3]; + y = y/256; buf[4] = (u_char)(y%256); y -= buf[4]; + y = y/256; buf[5] = (u_char)(y%256); y -= buf[5]; + y = y/256; buf[6] = (u_char)(y%256); y -= buf[6]; + y = y/256; buf[7] = (u_char)(y%256); if (x < 0) buf[7] |= 0x80; @@ -152,14 +152,15 @@ int bsdiff(int argc, char *argv[]) goto cleanup; } - if (((I = malloc((oldsize + 1) * sizeof(off_t))) == NULL) || - ((V = malloc((oldsize + 1) * sizeof(off_t))) == NULL)) { + if (((I = malloc(((size_t)oldsize + 1) * sizeof(off_t))) == NULL) || + ((V = malloc(((size_t)oldsize + 1) * sizeof(off_t))) == NULL)) { warn("Failed to allocate memory for I or V"); goto cleanup; } /* Do a suffix sort on the old file. */ - I[0] = oldsize; sais(old, I+1, oldsize); + I[0] = oldsize; + sais(old, I+1, (int)oldsize); free(V); V = NULL; @@ -170,8 +171,8 @@ int bsdiff(int argc, char *argv[]) goto cleanup; } - if (((db = malloc(newsize + 1)) == NULL) || - ((eb = malloc(newsize + 1)) == NULL)) { + if (((db = malloc((size_t)newsize + 1)) == NULL) || + ((eb = malloc((size_t)newsize + 1)) == NULL)) { warn("Failed to allocate memory for db or eb"); goto cleanup; } @@ -352,7 +353,7 @@ int bsdiff(int argc, char *argv[]) offtout(len - 32, header + 8); /* Write diff data */ - if (dblen && fwrite(db, dblen, 1, pf) != 1) { + if (dblen && fwrite(db, (size_t)dblen, 1, pf) != 1) { warn("fwrite"); goto cleanup; } @@ -365,7 +366,7 @@ int bsdiff(int argc, char *argv[]) offtout(newsize - len, header + 16); /* Write extra data */ - if (eblen && fwrite(eb, eblen, 1, pf) != 1) { + if (eblen && fwrite(eb, (size_t)eblen, 1, pf) != 1) { warn("fwrite"); goto cleanup; } From 1316707136301abd4be39aaa340f89f54db1f4ef Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 16 May 2016 22:30:48 -0400 Subject: [PATCH 14/17] Fix indentation with bspatch.c --- Vendor/bsdiff/bspatch.c | 244 ++++++++++++++++++++-------------------- 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/Vendor/bsdiff/bspatch.c b/Vendor/bsdiff/bspatch.c index 56d39dcb..753b78cd 100644 --- a/Vendor/bsdiff/bspatch.c +++ b/Vendor/bsdiff/bspatch.c @@ -46,48 +46,48 @@ typedef void* stream_t; typedef struct { - stream_t (*open)(FILE*); - void (*close)(stream_t); - off_t (*read)(stream_t, void*, off_t); + stream_t (*open)(FILE*); + void (*close)(stream_t); + off_t (*read)(stream_t, void*, off_t); } io_funcs_t; static stream_t BSDIFF40_open(FILE *f) { - int bzerr = 0; - BZFILE *s = NULL; + int bzerr = 0; + BZFILE *s = NULL; if ((s = BZ2_bzReadOpen(&bzerr, f, 0, 0, NULL, 0)) == NULL) { - warnx("BZ2_bzReadOpen, bz2err = %d", bzerr); + warnx("BZ2_bzReadOpen, bz2err = %d", bzerr); } - return s; + return s; } static void BSDIFF40_close(stream_t s) { - int bzerr; - BZ2_bzReadClose(&bzerr, (BZFILE*)s); + int bzerr; + BZ2_bzReadClose(&bzerr, (BZFILE*)s); } static off_t BSDIFF40_read(stream_t s, void *buf, off_t len) { - int bzerr = 0, lenread = 0; - lenread = BZ2_bzRead(&bzerr, (BZFILE*)s, buf, (int)len); + int bzerr = 0, lenread = 0; + lenread = BZ2_bzRead(&bzerr, (BZFILE*)s, buf, (int)len); if (bzerr != BZ_OK && bzerr != BZ_STREAM_END) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); lenread = -1; } - return lenread; + return lenread; } static io_funcs_t BSDIFF40_funcs = { - BSDIFF40_open, - BSDIFF40_close, - BSDIFF40_read + BSDIFF40_open, + BSDIFF40_close, + BSDIFF40_read }; static stream_t BSDIFN40_open(FILE *f) { - return f; + return f; } static void BSDIFN40_close(stream_t __unused s) @@ -96,13 +96,13 @@ static void BSDIFN40_close(stream_t __unused s) static off_t BSDIFN40_read(stream_t s, void *buf, off_t len) { - return (off_t)fread(buf, 1, (size_t)len, (FILE*)s); + return (off_t)fread(buf, 1, (size_t)len, (FILE*)s); } static io_funcs_t BSDIFN40_funcs = { - BSDIFN40_open, - BSDIFN40_close, - BSDIFN40_read + BSDIFN40_open, + BSDIFN40_close, + BSDIFN40_read }; @@ -112,35 +112,35 @@ typedef unsigned char u_char; static off_t offtin(u_char *buf) { - off_t y; + off_t y; - y=buf[7]&0x7F; - y=y*256;y+=buf[6]; - y=y*256;y+=buf[5]; - y=y*256;y+=buf[4]; - y=y*256;y+=buf[3]; - y=y*256;y+=buf[2]; - y=y*256;y+=buf[1]; - y=y*256;y+=buf[0]; + y=buf[7]&0x7F; + y=y*256;y+=buf[6]; + y=y*256;y+=buf[5]; + y=y*256;y+=buf[4]; + y=y*256;y+=buf[3]; + y=y*256;y+=buf[2]; + y=y*256;y+=buf[1]; + y=y*256;y+=buf[0]; - if(buf[7]&0x80) y=-y; + if(buf[7]&0x80) y=-y; - return y; + return y; } int bspatch(int argc,const char * const argv[]) { - FILE * f = NULL, * cpf = NULL, * dpf = NULL, * epf = NULL; - stream_t cstream = NULL, dstream = NULL, estream = NULL; - ssize_t oldsize = 0,newsize = 0; - ssize_t bzctrllen = 0,bzdatalen = 0; + FILE * f = NULL, * cpf = NULL, * dpf = NULL, * epf = NULL; + stream_t cstream = NULL, dstream = NULL, estream = NULL; + ssize_t oldsize = 0,newsize = 0; + ssize_t bzctrllen = 0,bzdatalen = 0; u_char header[32] = {0},buf[8] = {0}; - u_char *old = NULL, *new = NULL; - off_t oldpos = 0,newpos = 0; + u_char *old = NULL, *new = NULL; + off_t oldpos = 0,newpos = 0; off_t ctrl[3] = {0}; - off_t lenread = 0; - off_t i = 0; - io_funcs_t * io = NULL; + off_t lenread = 0; + off_t i = 0; + io_funcs_t * io = NULL; int exitstatus = -1; if(argc!=4) { @@ -148,101 +148,101 @@ int bspatch(int argc,const char * const argv[]) goto cleanup; } - /* Open patch file */ + /* Open patch file */ if ((f = fopen(argv[3], "r")) == NULL) { - warn("fopen(%s)", argv[3]); + warn("fopen(%s)", argv[3]); goto cleanup; } - /* - File format: - 0 8 "BSDIFF40" (bzip2) or "BSDIFN40" (raw) - 8 8 X - 16 8 Y - 24 8 sizeof(newfile) - 32 X bzip2(control block) - 32+X Y bzip2(diff block) - 32+X+Y ??? bzip2(extra block) - with control block a set of triples (x,y,z) meaning "add x bytes - from oldfile to x bytes from the diff block; copy y bytes from the - extra block; seek forwards in oldfile by z bytes". - */ + /* + File format: + 0 8 "BSDIFF40" (bzip2) or "BSDIFN40" (raw) + 8 8 X + 16 8 Y + 24 8 sizeof(newfile) + 32 X bzip2(control block) + 32+X Y bzip2(diff block) + 32+X+Y ??? bzip2(extra block) + with control block a set of triples (x,y,z) meaning "add x bytes + from oldfile to x bytes from the diff block; copy y bytes from the + extra block; seek forwards in oldfile by z bytes". + */ - /* Read header */ - if (fread(header, 1, 32, f) < 32) { + /* Read header */ + if (fread(header, 1, 32, f) < 32) { if (feof(f)) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); } else { warn("fread(%s)", argv[3]); } goto cleanup; - } + } - /* Check for appropriate magic */ - if (memcmp(header, "BSDIFF40", 8) == 0) - io = &BSDIFF40_funcs; - else if (memcmp(header, "BSDIFN40", 8) == 0) - io = &BSDIFN40_funcs; + /* Check for appropriate magic */ + if (memcmp(header, "BSDIFF40", 8) == 0) + io = &BSDIFF40_funcs; + else if (memcmp(header, "BSDIFN40", 8) == 0) + io = &BSDIFN40_funcs; else { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - /* Read lengths from header */ - bzctrllen=offtin(header+8); - bzdatalen=offtin(header+16); - newsize=offtin(header+24); + /* Read lengths from header */ + bzctrllen=offtin(header+8); + bzdatalen=offtin(header+16); + newsize=offtin(header+24); if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - /* Close patch file and re-open it via libbzip2 at the right places */ + /* Close patch file and re-open it via libbzip2 at the right places */ if (fclose(f)) { - warn("fclose(%s)", argv[3]); + warn("fclose(%s)", argv[3]); f = NULL; goto cleanup; } f = NULL; if ((cpf = fopen(argv[3], "r")) == NULL) { - warn("fopen(%s)", argv[3]); + warn("fopen(%s)", argv[3]); goto cleanup; } if (fseeko(cpf, 32, SEEK_SET)) { - warn("fseeko(%s, %lld)", argv[3], - (long long)32); + warn("fseeko(%s, %lld)", argv[3], + (long long)32); goto cleanup; } - cstream = io->open(cpf); + cstream = io->open(cpf); if (cstream == NULL) { warn("cstream open"); goto cleanup; } if ((dpf = fopen(argv[3], "r")) == NULL) { - warn("fopen(%s)", argv[3]); + warn("fopen(%s)", argv[3]); goto cleanup; } if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) { - warn("fseeko(%s, %lld)", argv[3], - (long long)(32 + bzctrllen)); + warn("fseeko(%s, %lld)", argv[3], + (long long)(32 + bzctrllen)); goto cleanup; } - dstream = io->open(dpf); + dstream = io->open(dpf); if (dstream == NULL) { warn("dstream open"); goto cleanup; } if ((epf = fopen(argv[3], "r")) == NULL) { - warn("fopen(%s)", argv[3]); + warn("fopen(%s)", argv[3]); goto cleanup; } if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) { - warn("fseeko(%s, %lld)", argv[3], - (long long)(32 + bzctrllen + bzdatalen)); + warn("fseeko(%s, %lld)", argv[3], + (long long)(32 + bzctrllen + bzdatalen)); goto cleanup; } - estream = io->open(epf); + estream = io->open(epf); if (estream == NULL) { warn("estream open"); goto cleanup; @@ -261,64 +261,64 @@ int bspatch(int argc,const char * const argv[]) goto cleanup; } - oldpos=0;newpos=0; - while(newposread(cstream, buf, 8); + oldpos=0;newpos=0; + while(newposread(cstream, buf, 8); if (lenread < 8) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - ctrl[i]=offtin(buf); - }; + ctrl[i]=offtin(buf); + }; - /* Sanity-check */ + /* Sanity-check */ if(newpos+ctrl[0]>newsize) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - /* Read diff string */ - lenread = io->read(dstream, new + newpos, ctrl[0]); + /* Read diff string */ + lenread = io->read(dstream, new + newpos, ctrl[0]); if (lenread < 0 || lenread < ctrl[0]) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - /* Add old data to diff string */ - for(i=0;i=0) && (oldpos+i=0) && (oldpos+inewsize) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - /* Read extra string */ - lenread = io->read(estream, new + newpos, ctrl[1]); + /* Read extra string */ + lenread = io->read(estream, new + newpos, ctrl[1]); if (lenread < 0 || lenread < ctrl[1]) { - warnx("Corrupt patch\n"); + warnx("Corrupt patch\n"); goto cleanup; } - /* Adjust pointers */ - newpos+=ctrl[1]; - oldpos+=ctrl[2]; - }; + /* Adjust pointers */ + newpos+=ctrl[1]; + oldpos+=ctrl[2]; + }; - /* Clean up the bzip2 reads */ - io->close(cstream); + /* Clean up the bzip2 reads */ + io->close(cstream); cstream = NULL; - io->close(dstream); + io->close(dstream); dstream = NULL; - io->close(estream); + io->close(estream); estream = NULL; if (fclose(cpf) != 0) { @@ -342,7 +342,7 @@ int bspatch(int argc,const char * const argv[]) } epf = NULL; - /* Write the new file */ + /* Write the new file */ f = fopen(argv[2], "w"); if (f == NULL) { warn("failed to write new file: %s", argv[2]); @@ -363,8 +363,8 @@ int bspatch(int argc,const char * const argv[]) exitstatus = 0; cleanup: - free(new); - free(old); + free(new); + free(old); if (f != NULL) { fclose(f); @@ -394,5 +394,5 @@ cleanup: fclose(cpf); } - return exitstatus; + return exitstatus; } From 64fd27d918fef0d8483d8eb89594713ff8e47d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Sun, 22 May 2016 23:07:03 +0100 Subject: [PATCH 15/17] Fix 10.7 compat in new code --- Sparkle/SUAppcast.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 5271a5cc..c7e8738c 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -128,7 +128,7 @@ if (!attrName) { continue; } - dictionary[attrName] = [attribute stringValue]; + [dictionary setObject:[attribute stringValue] forKey:attrName]; } return dictionary; } From 4d952e9961ae267b7019bb670bc68dea58d55bb0 Mon Sep 17 00:00:00 2001 From: Christian Tietze Date: Thu, 26 May 2016 10:43:29 +0200 Subject: [PATCH 16/17] add Carthage indicator --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f12f8868..d4cad9db 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,5 @@ -# Sparkle [![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle) [![Coverage Status](https://coveralls.io/repos/sparkle-project/Sparkle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkle-project/Sparkle?branch=master) sponsored by: MaxCDN +# Sparkle [![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle) [![Coverage Status](https://coveralls.io/repos/sparkle-project/Sparkle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkle-project/Sparkle?branch=master) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +sponsored by: MaxCDN An easy-to-use software update framework for Cocoa developers. From db232a263b8e08e052dbe8739fc60624b005716a Mon Sep 17 00:00:00 2001 From: Christian Tietze Date: Thu, 26 May 2016 10:44:15 +0200 Subject: [PATCH 17/17] add CocoaPods indicator --- README.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index d4cad9db..cc5ce8e1 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,4 @@ -# Sparkle [![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle) [![Coverage Status](https://coveralls.io/repos/sparkle-project/Sparkle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkle-project/Sparkle?branch=master) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -sponsored by: MaxCDN +# Sparkle [![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle) [![Coverage Status](https://coveralls.io/repos/sparkle-project/Sparkle/badge.svg?branch=master&service=github)](https://coveralls.io/github/sparkle-project/Sparkle?branch=master) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods](https://img.shields.io/cocoapods/v/Sparkle.svg?maxAge=2592000)]() sponsored by: MaxCDN An easy-to-use software update framework for Cocoa developers.