Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Cast to uint32_t to avoid undefined behavior in ...



details:   https://anonhg.NetBSD.org/src/rev/c10fcde939f7
branches:  trunk
changeset: 744527:c10fcde939f7
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Wed Feb 05 07:24:07 2020 +0000

description:
Cast to uint32_t to avoid undefined behavior in smsc_setmacaddress.
Found by kUBSan.

diffstat:

 sys/dev/usb/if_smsc.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r 17b7def94d4b -r c10fcde939f7 sys/dev/usb/if_smsc.c
--- a/sys/dev/usb/if_smsc.c     Wed Feb 05 07:18:16 2020 +0000
+++ b/sys/dev/usb/if_smsc.c     Wed Feb 05 07:24:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_smsc.c,v 1.63 2020/01/29 06:35:28 thorpej Exp $     */
+/*     $NetBSD: if_smsc.c,v 1.64 2020/02/05 07:24:07 msaitoh Exp $     */
 
 /*     $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */
 /*     $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.63 2020/01/29 06:35:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.64 2020/02/05 07:24:07 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -544,7 +544,8 @@
 
        DPRINTF("... %02jx:%0j2x:%02jx", addr[3], addr[4], addr[5], 0);
 
-       val = (addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8) | addr[0];
+       val = ((uint32_t)addr[3] << 24) | (addr[2] << 16) | (addr[1] << 8)
+           | addr[0];
        if ((err = smsc_writereg(un, SMSC_MAC_ADDRL, val)) != 0)
                goto done;
 



Home | Main Index | Thread Index | Old Index