netif: fix compilation warning in QueryDefaultGatewayImpl()
What changed, and why it matters
This is a build-fix change only. A developer fixed a compiler warning that caused compilation to fail on FreeBSD 15 because a system header changed the type of a constant used in a network-routing helper. There is no change to program logic, no security bug, and no way to exploit it.
No security action needed. Treat as a normal portability/build fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit resolves a -Wsign-compare warning/error in QueryDefaultGatewayImpl() on FreeBSD 15.0/Clang 19. FreeBSD 15 removed an explicit (int) cast from NLMSG_HDRLEN, so comparing it with the signed recv_result variable triggers -Werror. The patch selects a matching local type (recv_result_t) based on the signedness of NLMSG_HDRLEN and casts recv_result before passing it to NLMSG_OK. The loop behavior and data flow are unchanged; only the comparison’s operand types are adjusted to satisfy the compiler.
Changed components
src/common/netif.cppInspect captured patch +5 / −1
diff --git a/src/common/netif.cpp b/src/common/netif.cpp
index ed891f12..712188f5 100644
--- a/src/common/netif.cpp
+++ b/src/common/netif.cpp
@@ -34,6 +34,8 @@
#include <ifaddrs.h>
#endif
+#include <type_traits>
+
namespace {
//! Return CNetAddr for the specified OS-level network address.
@@ -134,7 +136,9 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
return std::nullopt;
}
- for (nlmsghdr* hdr = (nlmsghdr*)response; NLMSG_OK(hdr, recv_result); hdr = NLMSG_NEXT(hdr, recv_result)) {
+ using recv_result_t = std::conditional_t<std::is_signed_v<decltype(NLMSG_HDRLEN)>, int64_t, decltype(NLMSG_HDRLEN)>;
+
+ for (nlmsghdr* hdr = (nlmsghdr*)response; NLMSG_OK(hdr, static_cast<recv_result_t>(recv_result)); hdr = NLMSG_NEXT(hdr, recv_result)) {
if (!(hdr->nlmsg_flags & NLM_F_MULTI)) {
done = true;
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.