Skip to content

Commit 178cdd6

Browse files
authored
Fix bad file descriptor crashes (#97)
Explicitly close the pipe file handle after the data has been read.
1 parent d69f366 commit 178cdd6

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

Packages/Keychain/Sources/Keychain/Keychain.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public extension Keychain {
6464
guard let data = read(Data.self, usingQuery: query.rawQuery) else {
6565
return nil
6666
}
67-
return String(decoding: data, as: UTF8.self)
67+
return String(data: data, encoding: .utf8)
6868
}
6969

7070
func removePassword(forAccount account: String, belongingToService service: String) {

Packages/Keychain/Sources/Keychain/RSAPrivateKey.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public final class RSAPrivateKey {
2424
}
2525

2626
public convenience init?(_ data: Data) {
27-
let string = String(decoding: data, as: UTF8.self)
27+
guard let string = String(data: data, encoding: .utf8) else {
28+
return nil
29+
}
2830
self.init(string)
2931
}
3032

Packages/Shell/Sources/ShellData/ProcessShell.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ public struct ProcessShell: Shell {
1818
process.launchPath = executablePath
1919
process.standardInput = nil
2020
process.environment = environment
21-
process.launch()
21+
try process.run()
2222
let data = pipe.fileHandleForReading.readDataToEndOfFile()
23+
// Explicitly close the pipe file handle to prevent running out of file descriptors.
24+
// See https://github.com/swiftlang/swift/issues/57827
25+
try pipe.fileHandleForReading.close()
2326
process.waitUntilExit()
2427
guard process.terminationStatus == 0 else {
2528
throw ProcessShellError.unexpectedTerminationStatus(process.terminationStatus)
2629
}
27-
return String(decoding: data, as: UTF8.self)
30+
return String(data: data, encoding: .utf8) ?? ""
2831
} onCancel: {
2932
if sendableProcess.process.isRunning {
3033
sendableProcess.process.terminate()

xcconfigs/General.xcconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GENERATE_INFOPLIST_FILE = YES
22
CURRENT_PROJECT_VERSION = 1
3-
MARKETING_VERSION = 0.9.0
3+
MARKETING_VERSION = 0.10.1
44
DEVELOPMENT_TEAM = 566MC7D8D4
55
CODE_SIGN_STYLE = Automatic
66
CODE_SIGN_ENTITLEMENTS = Tartelet/Supporting files/Tartelet.entitlements

0 commit comments

Comments
 (0)