Source-Changes-HG archive

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

[src/trunk]: src/sys/net Correctly handle the return value of arpresolve, oth...



details:   https://anonhg.NetBSD.org/src/rev/8019178ccf67
branches:  trunk
changeset: 351036:8019178ccf67
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Jan 31 17:13:36 2017 +0000

description:
Correctly handle the return value of arpresolve, otherwise we either leak
memory or use some we already freed.

Sent on tech-net, ok christos

diffstat:

 sys/net/if_ecosubr.c   |  13 ++++++-------
 sys/net/if_tokensubr.c |  11 +++++++----
 2 files changed, 13 insertions(+), 11 deletions(-)

diffs (67 lines):

diff -r 5a6c3d8624f6 -r 8019178ccf67 sys/net/if_ecosubr.c
--- a/sys/net/if_ecosubr.c      Tue Jan 31 16:55:04 2017 +0000
+++ b/sys/net/if_ecosubr.c      Tue Jan 31 17:13:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ecosubr.c,v 1.50 2017/01/24 18:37:20 maxv Exp $     */
+/*     $NetBSD: if_ecosubr.c,v 1.51 2017/01/31 17:13:36 maxv Exp $     */
 
 /*-
  * Copyright (c) 2001 Ben Harris
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.50 2017/01/24 18:37:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.51 2017/01/31 17:13:36 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -194,12 +194,11 @@
 #ifdef INET
        case AF_INET:
                if (m->m_flags & M_BCAST)
-                       memcpy(ehdr.eco_dhost, eco_broadcastaddr,
-                           ECO_ADDR_LEN);
+                       memcpy(ehdr.eco_dhost, eco_broadcastaddr, ECO_ADDR_LEN);
+               else if ((error = arpresolve(ifp, rt, m, dst, ehdr.eco_dhost,
+                   sizeof(ehdr.eco_dhost))) != 0)
+                       return error == EWOULDBLOCK ? 0 : error;
 
-               else if (!arpresolve(ifp, rt, m, dst, ehdr.eco_dhost,
-                   sizeof(ehdr.eco_dhost)))
-                       return (0);     /* if not yet resolved */
                /* If broadcasting on a simplex interface, loopback a copy */
                if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
                        mcopy = m_copy(m, 0, (int)M_COPYALL);
diff -r 5a6c3d8624f6 -r 8019178ccf67 sys/net/if_tokensubr.c
--- a/sys/net/if_tokensubr.c    Tue Jan 31 16:55:04 2017 +0000
+++ b/sys/net/if_tokensubr.c    Tue Jan 31 17:13:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tokensubr.c,v 1.80 2017/01/24 18:37:20 maxv Exp $   */
+/*     $NetBSD: if_tokensubr.c,v 1.81 2017/01/31 17:13:36 maxv Exp $   */
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -92,7 +92,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.80 2017/01/24 18:37:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.81 2017/01/31 17:13:36 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -222,8 +222,11 @@
  */
                else {
                        struct llentry *la;
-                       if (!arpresolve(ifp, rt, m, dst, edst, sizeof(edst)))
-                               return (0);     /* if not yet resolved */
+
+                       error = arpresolve(ifp, rt, m, dst, edst, sizeof(edst));
+                       if (error != 0)
+                               return error == EWOULDBLOCK ? 0 : error;
+
                        la = rt->rt_llinfo;
                        KASSERT(la != NULL);
                        TOKEN_RIF_LLE_ASSERT(la);



Home | Main Index | Thread Index | Old Index