From 668d66c4e1f79081d1096c7cf63e807637b88237 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 29 Apr 2016 10:25:38 +0200 Subject: iface: Use getnameinfo() to get address from struct sockaddr_storage Use getnameinfo() instead of inet_ntop() with weird (and incorrect) pointer arithmetics to get the numeric address from a struct sockaddr_storage. This addresses CID 99692 & 99696 discovered by the Coverity scanner. Signed-off-by: Tobias Klauser --- iface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iface.c b/iface.c index 8c77c61..b069532 100644 --- a/iface.c +++ b/iface.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -143,8 +144,10 @@ static void iface_record_addr_del(struct iface_record *rec, struct sockaddr_stor rec->addrs = addrs; rec->size--; } else { - char as[INET6_ADDRSTRLEN]; - inet_ntop(addr->ss_family, addr + sizeof(addr->ss_family), as, sizeof(as)); + char as[NI_MAXHOST]; + if (getnameinfo((struct sockaddr *)addr, sizeof(*addr), + as, sizeof(as), NULL, 0, NI_NUMERICHOST)) + strncpy(as, "", sizeof(as) - 1); log_err("Address %s to delete not found in records\n", as); } } else if (rec->size == 1) { -- cgit v1.2.3-54-g00ecf