summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2018-07-26 20:45:01 +0100
committerSami Kerola <kerolasa@iki.fi>2018-10-03 20:28:46 +0100
commit027f92312434ccde7c6eb9070283cbd00d6cc5ce (patch)
tree2c078964dbdeb37b75b6ac21fe692a8b97849f21
parent5fd1979c87a09cbbc8aa76231cee509cb56fa268 (diff)
downloadiputils-027f92312434ccde7c6eb9070283cbd00d6cc5ce.tar.gz
rdisc: ensure pr_name() buffer is big enough
Values in buffer size definition can hold maxium lenght host name, longest possible IPv6 address, and space for decorations. Earlier code may have truncated names and addresses, that is unlikely ever wanted. Additionally this fixes following warning. rdisc.c:720:31: warning: ‘ (’ directive output may be truncated writing 2 bytes into a region of size between 1 and 1025 [-Wformat-truncation=] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r--rdisc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/rdisc.c b/rdisc.c
index 6abf6dd..423a8ec 100644
--- a/rdisc.c
+++ b/rdisc.c
@@ -714,7 +714,7 @@ char *pr_name(struct in_addr addr)
{
struct sockaddr_in sin = { .sin_family = AF_INET, .sin_addr = addr };
char hnamebuf[NI_MAXHOST] = "";
- static char buf[80];
+ static char buf[sizeof(hnamebuf) + INET6_ADDRSTRLEN + sizeof(" ()")];
getnameinfo((struct sockaddr *) &sin, sizeof sin, hnamebuf, sizeof hnamebuf, NULL, 0, 0);
snprintf(buf, sizeof buf, "%s (%s)", hnamebuf, inet_ntoa(addr));