Skip to content

Commit

Permalink
Fix EXC_BAD_ACCESS crash in async handler, Test for encryption (defau…
Browse files Browse the repository at this point in the history
…lt to off)
  • Loading branch information
amosavian committed Oct 31, 2019
1 parent 9e6e0d1 commit 7b460c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion AMSMB2.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "AMSMB2"
s.version = "2.3.1"
s.version = "2.4.0"
s.summary = "Swift framework to connect SMB2/3 shares"

# This description is used to generate tags and improve search results.
Expand Down
4 changes: 2 additions & 2 deletions AMSMB2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/libsmb2/lib";
MARKETING_VERSION = 2.3.1;
MARKETING_VERSION = 2.4.0;
OTHER_LDFLAGS = "";
"OTHER_LDFLAGS[sdk=appletvos*]" = "-lsmb2-tvos";
"OTHER_LDFLAGS[sdk=appletvsimulator*]" = "-lsmb2-tvos";
Expand Down Expand Up @@ -446,7 +446,7 @@
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/libsmb2/lib";
MARKETING_VERSION = 2.3.1;
MARKETING_VERSION = 2.4.0;
"OTHER_LDFLAGS[sdk=appletvos*]" = "-lsmb2-tvos";
"OTHER_LDFLAGS[sdk=appletvsimulator*]" = "-lsmb2-tvos";
"OTHER_LDFLAGS[sdk=iphoneos*]" = "-lsmb2-ios";
Expand Down
1 change: 1 addition & 0 deletions AMSMB2/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ extension SMB2Context {
}

static let generic_handler: smb2_command_cb = { smb2, status, command_data, cbdata in
guard let smb2 = smb2, smb2.pointee.fd >= 0 else { return }
guard let cbdata = cbdata?.bindMemory(to: CBData.self, capacity: 1).pointee else { return }
if status != SMB2_STATUS_SUCCESS {
cbdata.result = status
Expand Down
30 changes: 17 additions & 13 deletions AMSMB2Tests/AMSMB2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AMSMB2Tests: XCTestCase {
// Put setup code here. This method is called before the invocation of each test method in the class.
setenv("SMBServer", "smb://192.168.1.5/", 0)
setenv("SMBShare", "Files", 0)
setenv("SMBEncrypted", "0", 0)
}

override func tearDown() {
Expand Down Expand Up @@ -89,6 +90,9 @@ class AMSMB2Tests: XCTestCase {
return nil
}
}()
lazy var encrypted: Bool = {
return ProcessInfo.processInfo.environment["SMBEncrypted"] == "1"
}()

func testShareEnum() {
let expectation = self.expectation(description: #function)
Expand Down Expand Up @@ -138,7 +142,7 @@ class AMSMB2Tests: XCTestCase {
let expectation = self.expectation(description: #function)

let smb = AMSMB2(url: server, credential: credential)!
smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.attributesOfFileSystem(forPath: "/") { result in
Expand All @@ -162,7 +166,7 @@ class AMSMB2Tests: XCTestCase {
let expectation = self.expectation(description: #function)

let smb = AMSMB2(url: server, credential: credential)!
smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.contentsOfDirectory(atPath: "/") { result in
Expand All @@ -189,7 +193,7 @@ class AMSMB2Tests: XCTestCase {
let expectation = self.expectation(description: #function)

let smb = AMSMB2(url: server, credential: credential)!
smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.contentsOfDirectory(atPath: "/") { result in
Expand Down Expand Up @@ -224,7 +228,7 @@ class AMSMB2Tests: XCTestCase {

let smb = AMSMB2(url: server, credential: credential)!
smb.timeout = 20
smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.createDirectory(atPath: "testEmpty") { (error) in
Expand Down Expand Up @@ -292,7 +296,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: "writetest.dat", completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.write(data: data, toPath: "writetest.dat", progress: { (progress) -> Bool in
Expand Down Expand Up @@ -361,7 +365,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: file, completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.write(data: data, toPath: file, progress: nil) { (error) in
Expand Down Expand Up @@ -400,7 +404,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: "uploadtest.dat", completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.uploadItem(at: url, toPath: "uploadtest.dat", progress: { (progress) -> Bool in
Expand Down Expand Up @@ -449,7 +453,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: file, completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.write(stream: inputStream, toPath: file, progress: { (progress) -> Bool in
Expand Down Expand Up @@ -492,7 +496,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: file, completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.uploadItem(at: url, toPath: file, progress: nil) { (error) in
Expand Down Expand Up @@ -537,7 +541,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: "copyTestDest.dat", completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.write(data: data, toPath: "copyTest.dat", progress: nil) { (error) in
Expand Down Expand Up @@ -575,7 +579,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeFile(atPath: "moveTest", completionHandler: nil)
smb.removeFile(atPath: "moveTestDest", completionHandler: nil)
}
smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.createDirectory(atPath: "moveTest") { (error) in
Expand Down Expand Up @@ -603,7 +607,7 @@ class AMSMB2Tests: XCTestCase {
smb.removeDirectory(atPath: rootCopy, recursive: true, completionHandler: nil)
}

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.createDirectory(atPath: root) { (error) in
Expand Down Expand Up @@ -642,7 +646,7 @@ class AMSMB2Tests: XCTestCase {

let smb = AMSMB2(url: server, credential: credential)!

smb.connectShare(name: share) { (error) in
smb.connectShare(name: share, encrypted: encrypted) { (error) in
XCTAssertNil(error)

smb.removeDirectory(atPath: "removeTest", recursive: true, completionHandler: nil)
Expand Down

0 comments on commit 7b460c8

Please sign in to comment.