summaryrefslogtreecommitdiffstats
path: root/usr.bin/netstat/inet.c
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>1998-06-09 04:13:03 +0000
committerimp <imp@FreeBSD.org>1998-06-09 04:13:03 +0000
commit94f67b7ef56a6df8d3c217cd5cc00b14f2dc3ae2 (patch)
tree2c2c649064ac668209925f9fd0df49a380a5d9f1 /usr.bin/netstat/inet.c
parent41a9e1ce2d103396468b07dce9965543cd39f4db (diff)
downloadFreeBSD-src-94f67b7ef56a6df8d3c217cd5cc00b14f2dc3ae2.zip
FreeBSD-src-94f67b7ef56a6df8d3c217cd5cc00b14f2dc3ae2.tar.gz
o Use snprintf over sprintf.
o Use strncpy correctly. o Use enough buffer for line. Inspired by or Obtained from: Similar changes in OpenBSD
Diffstat (limited to 'usr.bin/netstat/inet.c')
-rw-r--r--usr.bin/netstat/inet.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 0a8eff6..417f7db 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -36,7 +36,7 @@
static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95";
*/
static const char rcsid[] =
- "$Id: inet.c,v 1.27 1998/05/15 20:19:15 wollman Exp $";
+ "$Id: inet.c,v 1.28 1998/05/19 16:00:55 pb Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -559,7 +559,7 @@ inetname(inp)
struct in_addr *inp;
{
register char *cp;
- static char line[50];
+ static char line[MAXHOSTNAMELEN + 1];
struct hostent *hp;
struct netent *np;
@@ -583,9 +583,10 @@ inetname(inp)
}
if (inp->s_addr == INADDR_ANY)
strcpy(line, "*");
- else if (cp)
- strcpy(line, cp);
- else {
+ else if (cp) {
+ strncpy(line, cp, sizeof(line) - 1);
+ line[sizeof(line) - 1] = '\0';
+ } else {
inp->s_addr = ntohl(inp->s_addr);
#define C(x) ((x) & 0xff)
sprintf(line, "%lu.%lu.%lu.%lu", C(inp->s_addr >> 24),
OpenPOWER on IntegriCloud