summaryrefslogtreecommitdiffstats
path: root/lib/libatm/ip_addr.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-02-21 16:29:10 +0000
committerharti <harti@FreeBSD.org>2004-02-21 16:29:10 +0000
commit18065b763bf77571a33d562af62e14b026dfe363 (patch)
treefe2e313e01126a57830d800b2e7f168bfd674194 /lib/libatm/ip_addr.c
parent44ed42c915c99946ac708aab8960ce671fa01574 (diff)
downloadFreeBSD-src-18065b763bf77571a33d562af62e14b026dfe363.zip
FreeBSD-src-18065b763bf77571a33d562af62e14b026dfe363.tar.gz
Fix a couple of potential buffer overflows.
Submitted by: christer.oberg@texonet.com
Diffstat (limited to 'lib/libatm/ip_addr.c')
-rw-r--r--lib/libatm/ip_addr.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/libatm/ip_addr.c b/lib/libatm/ip_addr.c
index a653207..d3a5276 100644
--- a/lib/libatm/ip_addr.c
+++ b/lib/libatm/ip_addr.c
@@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
+#include <stdio.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -118,7 +119,7 @@ get_ip_addr(const char *p)
const char *
format_ip_addr(const struct in_addr *addr)
{
- static char host_name[128];
+ static char host_name[MAXHOSTNAMELEN + 18];
char *ip_num;
struct hostent *ip_host;
@@ -143,16 +144,13 @@ format_ip_addr(const struct in_addr *addr)
* Look up name in DNS
*/
ip_host = gethostbyaddr((const char *)addr, sizeof(addr), AF_INET);
- if (ip_host && ip_host->h_name &&
- strlen(ip_host->h_name)) {
+ if (ip_host && ip_host->h_name && strlen(ip_host->h_name)) {
/*
* Return host name followed by dotted decimal address
*/
- strcpy(host_name, ip_host->h_name);
- strcat(host_name, " (");
- strcat(host_name, ip_num);
- strcat(host_name, ")");
- return(host_name);
+ snprintf(host_name, sizeof(host_name), "%s (%s)",
+ ip_host->h_name, ip_num);
+ return (host_name);
} else {
/*
* No host name -- just return dotted decimal address
OpenPOWER on IntegriCloud