summaryrefslogtreecommitdiffstats
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>1998-06-09 04:31:02 +0000
committerimp <imp@FreeBSD.org>1998-06-09 04:31:02 +0000
commit8c96be00ef748f03f9e7f9f5934e7b0d53d1c872 (patch)
tree4cac82b29697cfe595adc937f0a97621ae134760 /usr.bin/ftp
parent9a6732bd4e65d3bdaeb59e6b7cd0331484e1c331 (diff)
downloadFreeBSD-src-8c96be00ef748f03f9e7f9f5934e7b0d53d1c872.zip
FreeBSD-src-8c96be00ef748f03f9e7f9f5934e7b0d53d1c872.tar.gz
Don't assume that hp->h_lenght == 4. Be conservative in its use.
Submitted by: J. Assange a long time ago.
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/ftp.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 305acd1..8d92be24 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $Id: ftp.c,v 1.11 1997/12/13 20:38:17 pst Exp $ */
+/* $Id: ftp.c,v 1.12 1997/12/16 08:22:37 ache Exp $ */
/* $NetBSD: ftp.c,v 1.29.2.1 1997/11/18 01:01:04 mellon Exp $ */
/*
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$Id: ftp.c,v 1.11 1997/12/13 20:38:17 pst Exp $");
+__RCSID("$Id: ftp.c,v 1.12 1997/12/16 08:22:37 ache Exp $");
__RCSID_SOURCE("$NetBSD: ftp.c,v 1.29.2.1 1997/11/18 01:01:04 mellon Exp $");
#endif
#endif /* not lint */
@@ -95,8 +95,7 @@ hookup(host, port)
memset((void *)&hisctladdr, 0, sizeof(hisctladdr));
if (inet_aton(host, &hisctladdr.sin_addr) != 0) {
hisctladdr.sin_family = AF_INET;
- (void)strncpy(hostnamebuf, host, sizeof(hostnamebuf) - 1);
- hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
+ (void) strncpy(hostnamebuf, host, sizeof(hostnamebuf));
} else {
hp = gethostbyname(host);
if (hp == NULL) {
@@ -105,10 +104,11 @@ hookup(host, port)
return ((char *) 0);
}
hisctladdr.sin_family = hp->h_addrtype;
- memcpy(&hisctladdr.sin_addr, hp->h_addr, hp->h_length);
- (void)strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf) - 1);
- hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
+ memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
+ MIN(hp->h_length,sizeof(hisctladdr.sin_addr)));
+ (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
}
+ hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
hostname = hostnamebuf;
s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
if (s < 0) {
@@ -127,7 +127,8 @@ hookup(host, port)
errno = oerrno;
warn("connect to address %s", ia);
hp->h_addr_list++;
- memcpy(&hisctladdr.sin_addr, hp->h_addr, hp->h_length);
+ memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
+ MIN(hp->h_length,sizeof(hisctladdr.sin_addr)));
printf("Trying %s...\n",
inet_ntoa(hisctladdr.sin_addr));
(void)close(s);
OpenPOWER on IntegriCloud