diff options
author | Sami Kerola <kerolasa@iki.fi> | 2018-07-26 20:45:01 +0100 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2018-10-03 20:28:46 +0100 |
commit | 027f92312434ccde7c6eb9070283cbd00d6cc5ce (patch) | |
tree | 2c078964dbdeb37b75b6ac21fe692a8b97849f21 | |
parent | 5fd1979c87a09cbbc8aa76231cee509cb56fa268 (diff) | |
download | iputils-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.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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)); |