fix(macos): reject invalid gateway ports before tunnel setup (#128260)

This commit is contained in:
Peter Steinberger
2026-08-23 09:21:05 -07:00
committed by GitHub
parent 1d54ce376e
commit bf91e00d36
2 changed files with 18 additions and 3 deletions
@@ -122,12 +122,12 @@ enum GatewayEnvironment {
{
if let raw = environment["OPENCLAW_GATEWAY_PORT"] {
let trimmed = raw.trimmingCharacters(in: .whitespacesAndNewlines)
if let parsed = Int(trimmed), parsed > 0 { return parsed }
if let parsed = Int(trimmed), (1...65535).contains(parsed) { return parsed }
}
if let configPort, configPort > 0 {
if let configPort, (1...65535).contains(configPort) {
return configPort
}
return storedPort > 0 ? storedPort : profile.defaultGatewayPort
return (1...65535).contains(storedPort) ? storedPort : profile.defaultGatewayPort
}
static func expectedGatewayVersion() -> Semver? {
@@ -124,6 +124,21 @@ struct GatewayEnvironmentTests {
configPort: nil,
storedPort: 23001,
profile: work) == 23001)
#expect(GatewayEnvironment.resolvedGatewayPort(
environment: ["OPENCLAW_GATEWAY_PORT": "65536"],
configPort: 22001,
storedPort: 23001,
profile: work) == 22001)
#expect(GatewayEnvironment.resolvedGatewayPort(
environment: [:],
configPort: 65536,
storedPort: 23001,
profile: work) == 23001)
#expect(GatewayEnvironment.resolvedGatewayPort(
environment: [:],
configPort: nil,
storedPort: 65536,
profile: work) == work.defaultGatewayPort)
#expect(AppProfile(environment: [:]).defaultGatewayPort == 18789)
}