From eef96acd1aaf01ead9d9b9f8076a89083e7e3e87 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 23 Jun 2016 15:15:22 +0000 Subject: [PATCH] net.c: skip details of too short socket addresses, part 2 * net.c (sa_printers): Add minimal address length for each socket family. (print_sockaddr): Call socket family specific sockaddr printer only when socket address length is greater or equal the minimal address length for the socket family. --- net.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/net.c b/net.c index 19dc6d3c..239b407e 100644 --- a/net.c +++ b/net.c @@ -280,15 +280,18 @@ print_sockaddr_data_bt(const void *const buf, const int addrlen) typedef void (* const sockaddr_printer)(const void *const, const int); -static const sockaddr_printer sa_printers[] = { - [AF_UNIX] = print_sockaddr_data_un, - [AF_INET] = print_sockaddr_data_in, - [AF_IPX] = print_sockaddr_data_ipx, - [AF_INET6] = print_sockaddr_data_in6, - [AF_NETLINK] = print_sockaddr_data_nl, - [AF_PACKET] = print_sockaddr_data_ll, +static const struct { + const sockaddr_printer printer; + const int min_len; +} sa_printers[] = { + [AF_UNIX] = { print_sockaddr_data_un, SIZEOF_SA_FAMILY + 1 }, + [AF_INET] = { print_sockaddr_data_in, sizeof(struct sockaddr_in) }, + [AF_IPX] = { print_sockaddr_data_ipx, sizeof(struct sockaddr_ipx) }, + [AF_INET6] = { print_sockaddr_data_in6, SIN6_MIN_LEN }, + [AF_NETLINK] = { print_sockaddr_data_nl, SIZEOF_SA_FAMILY + 1 }, + [AF_PACKET] = { print_sockaddr_data_ll, sizeof(struct sockaddr_ll) }, #ifdef HAVE_BLUETOOTH_BLUETOOTH_H - [AF_BLUETOOTH] = print_sockaddr_data_bt, + [AF_BLUETOOTH] = { print_sockaddr_data_bt, SIZEOF_SA_FAMILY + 1 }, #endif }; @@ -300,12 +303,13 @@ print_sockaddr(struct tcb *tcp, const void *const buf, const int addrlen) tprints("{sa_family="); printxval(addrfams, sa->sa_family, "AF_???"); - if (addrlen > (int) sizeof(sa->sa_family)) { + if (addrlen > (int) SIZEOF_SA_FAMILY) { tprints(", "); if (sa->sa_family < ARRAY_SIZE(sa_printers) - && sa_printers[sa->sa_family]) { - sa_printers[sa->sa_family](buf, addrlen); + && sa_printers[sa->sa_family].printer + && addrlen >= sa_printers[sa->sa_family].min_len) { + sa_printers[sa->sa_family].printer(buf, addrlen); } else { print_sockaddr_data_raw(buf, addrlen); }