Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb copy a pattern from if_udav.c, which already had...



details:   https://anonhg.NetBSD.org/src/rev/b6b848e7f008
branches:  trunk
changeset: 844289:b6b848e7f008
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Aug 11 02:37:03 2019 +0000

description:
copy a pattern from if_udav.c, which already had "too much" check.

even though overflow or underflow is really unlikely here, reorder
various expressions to reduce the likelyhood even further.

diffstat:

 sys/dev/usb/if_axe.c  |  8 ++++----
 sys/dev/usb/if_axen.c |  8 ++++----
 sys/dev/usb/if_cdce.c |  8 ++++----
 sys/dev/usb/if_ure.c  |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)

diffs (117 lines):

diff -r d5d90ec8a470 -r b6b848e7f008 sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c      Sun Aug 11 01:31:19 2019 +0000
+++ b/sys/dev/usb/if_axe.c      Sun Aug 11 02:37:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axe.c,v 1.110 2019/08/11 01:04:33 mrg Exp $ */
+/*     $NetBSD: if_axe.c,v 1.111 2019/08/11 02:37:03 mrg Exp $ */
 /*     $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.110 2019/08/11 01:04:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.111 2019/08/11 02:37:03 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1192,9 +1192,9 @@
                        length, m->m_pkthdr.len, sizeof(hdr), 0);
        }
 
+       if (m->m_pkthdr.len > un->un_tx_bufsz - hdr_len - tlr_len)
+               return 0;
        length = hdr_len + m->m_pkthdr.len + tlr_len;
-       if (length > un->un_tx_bufsz)
-               return 0;
 
        if (hdr_len)
                memcpy(c->unc_buf, &hdr, hdr_len);
diff -r d5d90ec8a470 -r b6b848e7f008 sys/dev/usb/if_axen.c
--- a/sys/dev/usb/if_axen.c     Sun Aug 11 01:31:19 2019 +0000
+++ b/sys/dev/usb/if_axen.c     Sun Aug 11 02:37:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_axen.c,v 1.60 2019/08/11 01:04:33 mrg Exp $ */
+/*     $NetBSD: if_axen.c,v 1.61 2019/08/11 02:37:03 mrg Exp $ */
 /*     $OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $ */
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.60 2019/08/11 01:04:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.61 2019/08/11 02:37:03 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -863,9 +863,9 @@
 
        usbnet_isowned_tx(un);
 
+       if (m->m_pkthdr.len > un->un_tx_bufsz - sizeof(hdr))
+               return 0;
        length = m->m_pkthdr.len + sizeof(hdr);
-       if (length > un->un_tx_bufsz)
-               return 0;
 
        /* XXX Is this needed?  wMaxPacketSize? */
        switch (un->un_udev->ud_speed) {
diff -r d5d90ec8a470 -r b6b848e7f008 sys/dev/usb/if_cdce.c
--- a/sys/dev/usb/if_cdce.c     Sun Aug 11 01:31:19 2019 +0000
+++ b/sys/dev/usb/if_cdce.c     Sun Aug 11 02:37:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cdce.c,v 1.62 2019/08/11 01:04:33 mrg Exp $ */
+/*     $NetBSD: if_cdce.c,v 1.63 2019/08/11 02:37:03 mrg Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999, 2000-2003 Bill Paul <wpaul%windriver.com@localhost>
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.62 2019/08/11 01:04:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cdce.c,v 1.63 2019/08/11 02:37:03 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -305,9 +305,9 @@
        if (un->un_flags & CDCE_ZAURUS)
                extra = sizeof(crc);
 
+       if (m->m_pkthdr.len > un->un_tx_bufsz - extra)
+               return 0;
        length = m->m_pkthdr.len + extra;
-       if (length > un->un_tx_bufsz)
-               return 0;
 
        m_copydata(m, 0, m->m_pkthdr.len, c->unc_buf);
        if (un->un_flags & CDCE_ZAURUS) {
diff -r d5d90ec8a470 -r b6b848e7f008 sys/dev/usb/if_ure.c
--- a/sys/dev/usb/if_ure.c      Sun Aug 11 01:31:19 2019 +0000
+++ b/sys/dev/usb/if_ure.c      Sun Aug 11 02:37:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ure.c,v 1.22 2019/08/11 01:04:33 mrg Exp $  */
+/*     $NetBSD: if_ure.c,v 1.23 2019/08/11 02:37:04 mrg Exp $  */
 /*     $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
 
 /*-
@@ -30,7 +30,7 @@
 /* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.22 2019/08/11 01:04:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.23 2019/08/11 02:37:04 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1066,7 +1066,7 @@
 
        usbnet_isowned_tx(un);
 
-       if (m->m_pkthdr.len + sizeof(txhdr) > un->un_tx_bufsz)
+       if (m->m_pkthdr.len > un->un_tx_bufsz - sizeof(txhdr))
                return 0;
 
        /* header */



Home | Main Index | Thread Index | Old Index