From 02cb2931aa283147df78a0f972b2065429e2e8bc Mon Sep 17 00:00:00 2001 From: david Date: Sat, 1 Jun 2013 16:28:44 +0000 Subject: [PATCH] Fix rt_msghdr padding on NetBSD. NetBSD uses a fixed 64-bit padding, unlike OS X (32-bit), and unlike other platforms (sizeof(unsigned long)). There is an RT_ROUNDUP macro that does the right alignment; use that when available. http://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/lib/libc/net/getifaddrs.c http://fxr.watson.org/fxr/source/net/route.h?v=NETBSD#L270 Rounding to 4 bytes was breaking with IPv6 addresses, which are 28 bytes. The pointer was being advanced by 28 instead of 32. Compare to r29739, somewhat similar. Reported by Fredrik Pettai. http://seclists.org/nmap-dev/2013/q1/384 --- CHANGELOG | 2 ++ libdnet-stripped/NMAP_MODIFICATIONS | 23 +++++++++++++++++++++++ libdnet-stripped/src/route-bsd.c | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c5fe453d7..aaf79c446 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ # Nmap Changelog ($Id$); -*-text-*- +o Fixed IPv6 routing table alignment on NetBSD. + o [NSE] Added http-phpmyadmin-dir-traversal by Alexey Meshcheryakov. o Added a service probe for Erlang distribution nodes. diff --git a/libdnet-stripped/NMAP_MODIFICATIONS b/libdnet-stripped/NMAP_MODIFICATIONS index a5bc058a0..6a7cd40d7 100644 --- a/libdnet-stripped/NMAP_MODIFICATIONS +++ b/libdnet-stripped/NMAP_MODIFICATIONS @@ -1887,3 +1887,26 @@ index 4fe059c..184c077 100644 /* XXX - why must this happen before SIOCSIFADDR? */ if (addr_btos(entry->intf_addr.addr_bits, &ifr.ifr_addr) == 0) { + +o Use the RT_ROUNDUP preprocessor macro for 64-bit rt_msghdr alignment + on NetBSD. + +diff --git a/libdnet-stripped/src/route-bsd.c b/libdnet-stripped/src/route-bsd.c +index 44e7dd2..47f3705 100644 +--- a/libdnet-stripped/src/route-bsd.c ++++ b/libdnet-stripped/src/route-bsd.c +@@ -47,8 +47,14 @@ + + #include "dnet.h" + ++#ifdef RT_ROUNDUP ++/* NetBSD defines this macro rounding to 64-bit boundaries. ++ http://fxr.watson.org/fxr/ident?v=NETBSD;i=RT_ROUNDUP */ ++#define ROUNDUP(a) RT_ROUNDUP(a) ++#else + #define ROUNDUP(a) \ + ((a) > 0 ? (1 + (((a) - 1) | (RT_MSGHDR_ALIGNMENT - 1))) : RT_MSGHDR_ALIGNMENT) ++#endif + + #ifdef HAVE_SOCKADDR_SA_LEN + #define NEXTSA(s) \ diff --git a/libdnet-stripped/src/route-bsd.c b/libdnet-stripped/src/route-bsd.c index 44e7dd2f2..47f370522 100644 --- a/libdnet-stripped/src/route-bsd.c +++ b/libdnet-stripped/src/route-bsd.c @@ -47,8 +47,14 @@ #include "dnet.h" +#ifdef RT_ROUNDUP +/* NetBSD defines this macro rounding to 64-bit boundaries. + http://fxr.watson.org/fxr/ident?v=NETBSD;i=RT_ROUNDUP */ +#define ROUNDUP(a) RT_ROUNDUP(a) +#else #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (RT_MSGHDR_ALIGNMENT - 1))) : RT_MSGHDR_ALIGNMENT) +#endif #ifdef HAVE_SOCKADDR_SA_LEN #define NEXTSA(s) \