fix: harden device model decoding
This commit is contained in:
@@ -221,9 +221,10 @@ final class BridgeConnectionController {
|
|||||||
var systemInfo = utsname()
|
var systemInfo = utsname()
|
||||||
uname(&systemInfo)
|
uname(&systemInfo)
|
||||||
let machine = withUnsafeBytes(of: &systemInfo.machine) { ptr in
|
let machine = withUnsafeBytes(of: &systemInfo.machine) { ptr in
|
||||||
String(decoding: ptr.prefix { $0 != 0 }, as: UTF8.self)
|
String(bytes: ptr.prefix { $0 != 0 }, encoding: .utf8)
|
||||||
}
|
}
|
||||||
return machine.isEmpty ? "unknown" : machine
|
let trimmed = machine?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||||
|
return trimmed.isEmpty ? "unknown" : trimmed
|
||||||
}
|
}
|
||||||
|
|
||||||
private func appVersion() -> String {
|
private func appVersion() -> String {
|
||||||
|
|||||||
@@ -277,9 +277,10 @@ struct SettingsTab: View {
|
|||||||
var systemInfo = utsname()
|
var systemInfo = utsname()
|
||||||
uname(&systemInfo)
|
uname(&systemInfo)
|
||||||
let machine = withUnsafeBytes(of: &systemInfo.machine) { ptr in
|
let machine = withUnsafeBytes(of: &systemInfo.machine) { ptr in
|
||||||
String(decoding: ptr.prefix { $0 != 0 }, as: UTF8.self)
|
String(bytes: ptr.prefix { $0 != 0 }, encoding: .utf8)
|
||||||
}
|
}
|
||||||
return machine.isEmpty ? "unknown" : machine
|
let trimmed = machine?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||||
|
return trimmed.isEmpty ? "unknown" : trimmed
|
||||||
}
|
}
|
||||||
|
|
||||||
private func currentCaps() -> [String] {
|
private func currentCaps() -> [String] {
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ enum InstanceIdentity {
|
|||||||
guard sysctlbyname("hw.model", &buffer, &size, nil, 0) == 0 else { return nil }
|
guard sysctlbyname("hw.model", &buffer, &size, nil, 0) == 0 else { return nil }
|
||||||
|
|
||||||
let bytes = buffer.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }
|
let bytes = buffer.prefix { $0 != 0 }.map { UInt8(bitPattern: $0) }
|
||||||
let s = String(decoding: bytes, as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
|
guard let raw = String(bytes: bytes, encoding: .utf8) else { return nil }
|
||||||
return s.isEmpty ? nil : s
|
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
return trimmed.isEmpty ? nil : trimmed
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user