Merge branch 'master' into ui-separation-and-xpc

This commit is contained in:
Zorg committed 2016-05-27 16:30:13 -04:00
commit 7df7222fe4
8 files changed
+240 -145

No files matched your search

+21
View File
@@ -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)
+1 -1
View File
@@ -1,4 +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) <a href="https://www.maxcdn.com/?utm_source=sparkle-github&amp;utm_medium=badge&amp;utm_campaign=readme"><img src="https://img.shields.io/badge/sponsored%20by-MaxCDN-orange.svg" alt="sponsored by: MaxCDN"></a>
# 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)]() <a href="https://www.maxcdn.com/?utm_source=sparkle-github&amp;utm_medium=badge&amp;utm_campaign=readme"><img src="https://img.shields.io/badge/sponsored%20by-MaxCDN-orange.svg" alt="sponsored by: MaxCDN"></a>
An easy-to-use software update framework for Cocoa developers.
+8 -2
View File
@@ -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, ); }; };
@@ -73,13 +73,14 @@
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 */; };
5D06E8FF0FD68D6D005AE3F6 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; };
5D06E9050FD68D7D005AE3F6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; };
5D1AF58B0FD7678C0065DB48 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; };
5D1AF5900FD767AD0065DB48 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */; };
5D1AF59A0FD767E50065DB48 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5990FD767E50065DB48 /* libz.dylib */; };
5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5F1510A11C96E591006E1629 /* testnamespaces.xml */; settings = {ASSET_TAGS = (); }; };
6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */; settings = {ATTRIBUTES = (); }; };
6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (); }; };
61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */; settings = {ATTRIBUTES = (); }; };
@@ -690,6 +691,7 @@
5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxar.1.dylib; path = usr/lib/libxar.1.dylib; sourceTree = SDKROOT; };
5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
5D1AF5990FD767E50065DB48 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
5F1510A11C96E591006E1629 /* testnamespaces.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testnamespaces.xml; sourceTree = "<group>"; };
6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPipedUnarchiver.h; sourceTree = "<group>"; };
6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUDiskImageUnarchiver.h; sourceTree = "<group>"; };
6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDiskImageUnarchiver.m; sourceTree = "<group>"; };
@@ -1253,6 +1255,7 @@
14958C6C19AEBC610061B14F /* test-pubkey.pem */,
5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */,
5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */,
5F1510A11C96E591006E1629 /* testnamespaces.xml */,
);
path = Resources;
sourceTree = "<group>";
@@ -2210,6 +2213,7 @@
buildActionMask = 2147483647;
files = (
14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */,
5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */,
72AC6B2E1B9B218C00F62325 /* SparkleTestCodeSignApp.dmg in Resources */,
C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */,
72AC6B281B9AAD6700F62325 /* SparkleTestCodeSignApp.tar in Resources */,
@@ -2492,6 +2496,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 */,
725F97771C8A62F500265BE4 /* SUAdHocCodeSigning.m in Sources */,
@@ -2638,6 +2643,7 @@
725CB95B1C7121830064365A /* SUStandardUserDriver.m in Sources */,
61EF67560E25B58D00F754E0 /* SUHost.m in Sources */,
55C14F07136EF6DB00649790 /* SULog.m in Sources */,
723B252D1CEAB3A600909873 /* bscommon.c in Sources */,
726F2CE61BC9C33D001971A4 /* SUOperatingSystem.m in Sources */,
72B767D31C9C7B9300A07552 /* SUProbingUpdateDriver.m in Sources */,
7293A1AF1CEE933800B957A7 /* SUURLRequest.m in Sources */,
+30 -3
View File
@@ -110,6 +110,33 @@
});
}
- (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 setObject:[attribute stringValue] forKey:attrName];
}
return dictionary;
}
-(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);
return [@"sparkle:" stringByAppendingString:localName];
} else {
return [node name]; // Backwards compatibility
}
}
-(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData error:(NSError *__autoreleasing*)errorp {
NSUInteger options = NSXMLNodeLoadExternalEntitiesNever; // Prevent inclusion from file://
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:appcastData options:options error:errorp];
@@ -134,7 +161,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 objectForKey:name];
if (nodes == nil) {
@@ -151,7 +178,7 @@
node = [self bestNodeInNodes:[nodesDict objectForKey: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 setObject:encDict forKey:name];
}
else if ([name isEqualToString:SURSSElementPubDate]) {
@@ -168,7 +195,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 setObject:deltas forKey:name];
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:customNS="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>For unit test only</title>
<item>
<title>Version 3.0</title>
<pubDate>Sat, 26 Jul 2014 15:20:12 +0000</pubDate>
<customNS:releaseNotesLink>https://sparkle-project.org/#works</customNS:releaseNotesLink>
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" customNS:version="3.0" />
</item>
<item>
<title>Version 2.0</title>
<description>desc</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<enclosure url="http://0.0.0.0:1337/Sparkle_Test_App.zip" customNS:version="2.0" />
</item>
</channel>
</rss>
+23 -1
View File
@@ -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 testData = NSData(contentsOfFile: testFile)!
@@ -61,4 +61,26 @@ class SUAppcastTest: XCTestCase {
XCTFail(err.localizedDescription);
}
}
func testNamespaces() {
let appcast = SUAppcast();
let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testnamespaces", ofType: "xml")!;
let testFileUrl = NSURL(fileURLWithPath: testFile);
XCTAssertNotNil(testFileUrl);
do {
let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem];
XCTAssertEqual(2, items.count);
XCTAssertEqual("Version 2.0", items[1].title);
XCTAssertEqual("desc", items[1].itemDescription);
XCTAssertNotNil(items[0].releaseNotesURL);
XCTAssertEqual("https://sparkle-project.org/#works", items[0].releaseNotesURL!.absoluteString);
} catch let err as NSError {
NSLog("%@", err);
XCTFail(err.localizedDescription);
}
}
}
+17 -16
View File
@@ -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;
}
+122 -122
View File
@@ -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(newpos<newsize) {
/* Read control data */
for(i=0;i<=2;i++) {
lenread = io->read(cstream, buf, 8);
oldpos=0;newpos=0;
while(newpos<newsize) {
/* Read control data */
for(i=0;i<=2;i++) {
lenread = io->read(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<ctrl[0];i++)
if((oldpos+i>=0) && (oldpos+i<oldsize))
new[newpos+i]+=old[oldpos+i];
/* Add old data to diff string */
for(i=0;i<ctrl[0];i++)
if((oldpos+i>=0) && (oldpos+i<oldsize))
new[newpos+i]+=old[oldpos+i];
/* Adjust pointers */
newpos+=ctrl[0];
oldpos+=ctrl[0];
/* Adjust pointers */
newpos+=ctrl[0];
oldpos+=ctrl[0];
/* Sanity-check */
/* Sanity-check */
if(newpos+ctrl[1]>newsize) {
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;
}