Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/tftp make sure we do not overrun peeraddr.



details:   https://anonhg.NetBSD.org/src/rev/10195132087b
branches:  trunk
changeset: 499518:10195132087b
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Nov 21 14:28:54 2000 +0000

description:
make sure we do not overrun peeraddr.

diffstat:

 usr.bin/tftp/main.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (35 lines):

diff -r 97a3601a5e6d -r 10195132087b usr.bin/tftp/main.c
--- a/usr.bin/tftp/main.c       Tue Nov 21 14:21:36 2000 +0000
+++ b/usr.bin/tftp/main.c       Tue Nov 21 14:28:54 2000 +0000
@@ -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 @@
 #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 @@
        }
 
        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 @@
        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,



Home | Main Index | Thread Index | Old Index