Skip to content
Open
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
11 changes: 10 additions & 1 deletion Sources/Services/Network/Server/DefaultNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ public actor DefaultNetworkService: NetworkService {
}

let subnet = status.ipv4Subnet
let size = Int(subnet.upper.value - subnet.lower.value - 3)
// Widen to Int before subtracting: doing the arithmetic in UInt32 traps
// on underflow when the subnet is too small (e.g. a /31 where
// upper - lower < 3).
let size = Int(subnet.upper.value) - Int(subnet.lower.value) - 3
guard size > 0 else {
throw ContainerizationError(
.invalidState,
message: "network \(network.id) subnet is too small to allocate addresses"
)
}
self.network = network
self.log = log
self.allocator = try AttachmentAllocator(lower: subnet.lower.value + 2, size: size)
Expand Down