make sure we do not overrun peeraddr.

This commit is contained in:
itojun 2000-11-21 14:28:54 +00:00
parent 20ef6ae40a
commit 44442755b9
1 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.12 1999/07/12 20:50:54 itojun Exp $ */
/* $NetBSD: main.c,v 1.13 2000/11/21 14:28:54 itojun Exp $ */
/*
* Copyright (c) 1983, 1993
@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: main.c,v 1.12 1999/07/12 20:50:54 itojun Exp $");
__RCSID("$NetBSD: main.c,v 1.13 2000/11/21 14:28:54 itojun Exp $");
#endif
#endif /* not lint */
@ -201,6 +201,8 @@ setpeer0(host, port)
}
for (res = res0; res; res = res->ai_next) {
if (res->ai_addrlen > sizeof(peeraddr))
continue;
f = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (f < 0) {
cause = "socket";
@ -223,6 +225,7 @@ setpeer0(host, port)
if (f < 0)
warn("%s", cause);
else {
/* res->ai_addr <= sizeof(peeraddr) is guaranteed */
memcpy(&peeraddr, res->ai_addr, res->ai_addrlen);
if (res->ai_canonname) {
(void) strncpy(hostname, res->ai_canonname,