From 8fe17af9a71e3617b179085a3e46f3f6c06b1278 Mon Sep 17 00:00:00 2001 From: Jeremy Visser Date: Thu, 24 Dec 2020 19:19:22 +1100 Subject: [PATCH] NetServer: set B_UNCONFIGURED_ADDRESS_FAMILIES flag for IPv6 link local mask In NetServer::_ConfigureIPv6LinkLocal, it was observed that the IPv6 link local addresses being added by the function had invalid masks applied, which upon investigation turned out to be uninitialised memory. It turns out that this call: BNetworkAddress localLinkMask("ffff:ffff:ffff:ffff::"); ...internally relies on getaddrinfo(), which only works if the OS already has an IPv6 address. Since this is the first IPv6 address, this will always fail. Since the error code is not checked, this results in uninitialised memory being used as the IPv6 mask. There are a variety of possible ways to solve this problem, but the one presented here passes the B_UNCONFIGURED_ADDRESS_FAMILIES flag which tells the resolver to always resolve IPv6 addresses. Change-Id: Ic1fbbd7cffdc6ec87cf160b9d7b02f077d2cf659 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3548 Reviewed-by: Adrien Destugues --- src/servers/net/NetServer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/servers/net/NetServer.cpp b/src/servers/net/NetServer.cpp index 6e5eb82160..167379d3c5 100644 --- a/src/servers/net/NetServer.cpp +++ b/src/servers/net/NetServer.cpp @@ -888,8 +888,16 @@ NetServer::_ConfigureIPv6LinkLocal(const char* name) addressRaw.s6_addr[15] = mac[5]; BNetworkAddress localLinkAddress(addressRaw, 0); - BNetworkAddress localLinkMask("ffff:ffff:ffff:ffff::"); // 64 - BNetworkAddress localLinkBroadcast("fe80::ffff:ffff:ffff:ffff"); + BNetworkAddress localLinkMask( + AF_INET6, + "ffff:ffff:ffff:ffff::", // 64 + (uint16)0, + B_UNCONFIGURED_ADDRESS_FAMILIES); + BNetworkAddress localLinkBroadcast( + AF_INET6, + "fe80::ffff:ffff:ffff:ffff", + (uint16)0, + B_UNCONFIGURED_ADDRESS_FAMILIES); if (interface.FindAddress(localLinkAddress) >= 0) { // uhoh... already has a local link address