Skip to content

Commit 9b9907d

Browse files
authored
Make the vmnet caller responsible for a zoneless prefix
Per review, the vmnet path no longer strips the zone itself. It renders `lower` as-is and checks the `inet_pton` result, so a prefix it cannot parse is rejected instead of quietly accepted, leaving the caller responsible for supplying a zoneless prefix. Checking the result also closes a pre-existing hole: it was discarded, so an address `inet_pton` refused left the buffer zeroed and configured `::`.
1 parent b5fc254 commit 9b9907d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Sources/Containerization/VmnetNetwork.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,13 @@ public struct VmnetNetwork: Network {
291291

292292
private static func configurePrefixV6(_ config: vmnet_network_configuration_ref, prefixV6: CIDRv6) throws {
293293
var p = in6_addr()
294-
// `inet_pton` rejects a zone suffix, so render the network address on
295-
// its own. A vmnet prefix is never link-scoped, so dropping the zone
296-
// here loses nothing.
297-
inet_pton(AF_INET6, IPv6Address(prefixV6.lower.value).description, &p)
294+
// `inet_pton` rejects a zone suffix, and a vmnet prefix is never
295+
// link-scoped, so the caller is responsible for supplying a zoneless
296+
// prefix. Check the result: ignoring it leaves `p` zeroed and
297+
// configures `::` on anything that fails to parse.
298+
guard inet_pton(AF_INET6, prefixV6.lower.description, &p) == 1 else {
299+
throw ContainerizationError(.invalidArgument, message: "invalid IPv6 prefix \(prefixV6) for network")
300+
}
298301

299302
guard vmnet_network_configuration_set_ipv6_prefix(config, &p, prefixV6.prefix.length) == .VMNET_SUCCESS else {
300303
throw ContainerizationError(.internalError, message: "failed to set IPv6 prefix \(prefixV6) for network")

0 commit comments

Comments
 (0)