diff --git a/Sparkle/SUBinaryDeltaCreate.m b/Sparkle/SUBinaryDeltaCreate.m index 185ed855..2ba65b52 100644 --- a/Sparkle/SUBinaryDeltaCreate.m +++ b/Sparkle/SUBinaryDeltaCreate.m @@ -81,6 +81,23 @@ static NSDictionary *infoForFile(FTSENT *ent) return @{INFO_HASH_KEY: hash, INFO_TYPE_KEY: @(ent->fts_info), INFO_PERMISSIONS_KEY : @(permissions), INFO_SIZE_KEY: @(size)}; } +static bool aclExists(const FTSENT *ent) +{ + // OS X does not currently support ACLs for symlinks + if (ent->fts_info == FTS_SL) { + return NO; + } + + acl_t acl = acl_get_link_np(ent->fts_path, ACL_TYPE_EXTENDED); + if (acl != NULL) { + acl_entry_t entry; + int result = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry); + assert(acl_free((void *)acl) == 0); + return (result == 0); + } + return false; +} + static NSString *absolutePath(NSString *path) { NSURL *url = [[NSURL alloc] initFileURLWithPath:path]; @@ -196,6 +213,11 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi return 1; } originalTreeState[key] = info; + + if (aclExists(ent)) { + fprintf(stderr, "Diffing ACLs are not supported. Detected ACL in before-tree on file %s", ent->fts_path); + return 1; + } } fts_close(fts); @@ -243,7 +265,12 @@ int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFi mode_t permissions = [info[INFO_PERMISSIONS_KEY] unsignedShortValue]; if (!IS_VALID_PERMISSIONS(permissions)) { - fprintf(stderr, "Invalid file permissions after tree on file %s\nOnly permissions with modes 0755 and 0644 are supported", ent->fts_path); + fprintf(stderr, "Invalid file permissions after-tree on file %s\nOnly permissions with modes 0755 and 0644 are supported", ent->fts_path); + return 1; + } + + if (aclExists(ent)) { + fprintf(stderr, "Diffing ACLs are not supported. Detected ACL in after-tree on file %s", ent->fts_path); return 1; } diff --git a/Tests/SUBinaryDeltaTest.m b/Tests/SUBinaryDeltaTest.m index 00a7d872..5ff66859 100644 --- a/Tests/SUBinaryDeltaTest.m +++ b/Tests/SUBinaryDeltaTest.m @@ -597,6 +597,107 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec }]; } +- (void)testInvalidRegularFileWithACLInBeforeTree +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString * __unused destinationDirectory) { + NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:sourceFile atomically:YES]); + + acl_t acl = acl_init(1); + + acl_entry_t entry; + XCTAssertEqual(0, acl_create_entry(&acl, &entry)); + + acl_permset_t permset; + XCTAssertEqual(0, acl_get_permset(entry, &permset)); + + XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH)); + + XCTAssertEqual(0, acl_set_link_np([sourceFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl)); + + XCTAssertEqual(0, acl_free(acl)); + } afterDiffHandler:nil]; + + XCTAssertFalse(success); +} + +- (void)testInvalidRegularFileWithACLInAfterTree +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *__unused sourceDirectory, NSString *destinationDirectory) { + NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]); + + acl_t acl = acl_init(1); + + acl_entry_t entry; + XCTAssertEqual(0, acl_create_entry(&acl, &entry)); + + acl_permset_t permset; + XCTAssertEqual(0, acl_get_permset(entry, &permset)); + + XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH)); + + XCTAssertEqual(0, acl_set_link_np([destinationFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl)); + + XCTAssertEqual(0, acl_free(acl)); + + } afterDiffHandler:nil]; + + XCTAssertFalse(success); +} + +- (void)testInvalidDirectoryWithACLInBeforeTree +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString * __unused destinationDirectory) { + NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([fileManager createDirectoryAtPath:sourceFile withIntermediateDirectories:NO attributes:nil error:nil]); + + acl_t acl = acl_init(1); + + acl_entry_t entry; + XCTAssertEqual(0, acl_create_entry(&acl, &entry)); + + acl_permset_t permset; + XCTAssertEqual(0, acl_get_permset(entry, &permset)); + + XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH)); + + XCTAssertEqual(0, acl_set_link_np([sourceFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl)); + + XCTAssertEqual(0, acl_free(acl)); + } afterDiffHandler:nil]; + + XCTAssertFalse(success); +} + +- (void)testInvalidDirectoryWithACLInAfterTree +{ + BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *fileManager, NSString * __unused sourceDirectory, NSString *destinationDirectory) { + NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"]; + + XCTAssertTrue([fileManager createDirectoryAtPath:destinationFile withIntermediateDirectories:NO attributes:nil error:nil]); + + acl_t acl = acl_init(1); + + acl_entry_t entry; + XCTAssertEqual(0, acl_create_entry(&acl, &entry)); + + acl_permset_t permset; + XCTAssertEqual(0, acl_get_permset(entry, &permset)); + + XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH)); + + XCTAssertEqual(0, acl_set_link_np([destinationFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl)); + + XCTAssertEqual(0, acl_free(acl)); + } afterDiffHandler:nil]; + + XCTAssertFalse(success); +} + - (void)testRegularFileToSymlinkChange { [self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {