Fix Zac's crash (#284)

* Guard + copy

* obo
This commit is contained in:
Max Goedjen 2021-12-23 22:56:47 -08:00 committed by GitHub
parent cda56ea14b
commit 9aacd73673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -23,8 +23,8 @@ extension Agent {
public func handle(reader: FileHandleReader, writer: FileHandleWriter) { public func handle(reader: FileHandleReader, writer: FileHandleWriter) {
Logger().debug("Agent handling new data") Logger().debug("Agent handling new data")
let data = reader.availableData let data = Data(reader.availableData)
guard !data.isEmpty else { return } guard data.count > 4 else { return }
let requestTypeInt = data[4] let requestTypeInt = data[4]
guard let requestType = SSHAgent.RequestType(rawValue: requestTypeInt) else { guard let requestType = SSHAgent.RequestType(rawValue: requestTypeInt) else {
writer.write(OpenSSHKeyWriter().lengthAndData(of: SSHAgent.ResponseType.agentFailure.data)) writer.write(OpenSSHKeyWriter().lengthAndData(of: SSHAgent.ResponseType.agentFailure.data))