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/2afba096f348
branches:  trunk
changeset: 370082:2afba096f348
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Sep 16 07:35:44 2022 +0000

description:
Cast to uint32_t to avoid undefined behavior in UGETDW(). Found by kUBSan.

diffstat:

 sys/dev/usb/usb.h |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (19 lines):

diff -r 328a3eab7e3c -r 2afba096f348 sys/dev/usb/usb.h
--- a/sys/dev/usb/usb.h Fri Sep 16 07:34:36 2022 +0000
+++ b/sys/dev/usb/usb.h Fri Sep 16 07:35:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.h,v 1.120 2022/04/17 13:15:37 riastradh Exp $      */
+/*     $NetBSD: usb.h,v 1.121 2022/09/16 07:35:44 msaitoh Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -78,7 +78,8 @@
 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
 #define USETW(w,v) ((w)[0] = (uint8_t)(v), (w)[1] = (uint8_t)((v) >> 8))
 #define USETWD(val) { (uint8_t)(val), (uint8_t)((val) >> 8) }
-#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
+#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) |   \
+           ((uint32_t)(w)[3] << 24))
 #define USETDW(w,v) ((w)[0] = (uint8_t)(v), \
                     (w)[1] = (uint8_t)((v) >> 8), \
                     (w)[2] = (uint8_t)((v) >> 16), \



Home | Main Index | Thread Index | Old Index