Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad file descriptor crashes #97

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Packages/Keychain/Sources/Keychain/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public extension Keychain {
guard let data = read(Data.self, usingQuery: query.rawQuery) else {
return nil
}
return String(decoding: data, as: UTF8.self)
return String(data: data, encoding: .utf8)
}

func removePassword(forAccount account: String, belongingToService service: String) {
Expand Down
4 changes: 3 additions & 1 deletion Packages/Keychain/Sources/Keychain/RSAPrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public final class RSAPrivateKey {
}

public convenience init?(_ data: Data) {
let string = String(decoding: data, as: UTF8.self)
guard let string = String(data: data, encoding: .utf8) else {
return nil
}
self.init(string)
}

Expand Down
7 changes: 5 additions & 2 deletions Packages/Shell/Sources/ShellData/ProcessShell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ public struct ProcessShell: Shell {
process.launchPath = executablePath
process.standardInput = nil
process.environment = environment
process.launch()
try process.run()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
// Explicitly close the pipe file handle to prevent running out of file descriptors.
// See https://github.com/swiftlang/swift/issues/57827
try pipe.fileHandleForReading.close()
process.waitUntilExit()
guard process.terminationStatus == 0 else {
throw ProcessShellError.unexpectedTerminationStatus(process.terminationStatus)
}
return String(decoding: data, as: UTF8.self)
return String(data: data, encoding: .utf8) ?? ""
} onCancel: {
if sendableProcess.process.isRunning {
sendableProcess.process.terminate()
Expand Down
2 changes: 1 addition & 1 deletion xcconfigs/General.xcconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GENERATE_INFOPLIST_FILE = YES
CURRENT_PROJECT_VERSION = 1
MARKETING_VERSION = 0.9.0
MARKETING_VERSION = 0.10.1
DEVELOPMENT_TEAM = 566MC7D8D4
CODE_SIGN_STYLE = Automatic
CODE_SIGN_ENTITLEMENTS = Tartelet/Supporting files/Tartelet.entitlements
Expand Down