From f3ffc9fdf90ffebc7544d217976ef0b480f06f39 Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Thu, 5 Nov 2015 11:02:28 +0000 Subject: [PATCH] Use returned network name from getnetbyaddr() correctly. --- usr.bin/netstat/route.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 2ab35a0ffd7..3f6918cc160 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -637,14 +637,13 @@ netname4(in_addr_t in, in_addr_t mask) trimdomain(cp, strlen(cp)); } } - inet_ntop(AF_INET, &in, nline, sizeof(line)); - if (cp != NULL) { - if (strcpy(cp, nline) != 0) - return (line); + if (cp != NULL) strlcpy(line, cp, sizeof(line)); - } else + else { + inet_ntop(AF_INET, &in, nline, sizeof(nline)); strlcpy(line, nline, sizeof(line)); - domask(line + strlen(line), i, ntohl(mask)); + domask(line + strlen(line), i, ntohl(mask)); + } return (line); }