Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/scsipi Avoid undefined behavior in scsipiconf.h in _...



details:   https://anonhg.NetBSD.org/src/rev/d23a2cd31aef
branches:  trunk
changeset: 362976:d23a2cd31aef
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 04 03:17:01 2018 +0000

description:
Avoid undefined behavior in scsipiconf.h in _4ltol() and _4btol()

Do not shift (through integer promotion) a signed value in an operation
than can change the bit of signedness.

sys/dev/scsipi/scsipiconf.h:808:17, left shift of 255 by 24 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>

diffstat:

 sys/dev/scsipi/scsipiconf.h |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (39 lines):

diff -r 3fd705b119d6 -r d23a2cd31aef sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h       Wed Jul 04 03:00:46 2018 +0000
+++ b/sys/dev/scsipi/scsipiconf.h       Wed Jul 04 03:17:01 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipiconf.h,v 1.126 2016/11/29 03:23:00 mlelstv Exp $ */
+/*     $NetBSD: scsipiconf.h,v 1.127 2018/07/04 03:17:01 kamil Exp $   */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2004 The NetBSD Foundation, Inc.
@@ -805,10 +805,10 @@
 {
        u_int32_t rv;
 
-       rv = (bytes[0] << 24) |
-            (bytes[1] << 16) |
-            (bytes[2] << 8) |
-            bytes[3];
+       rv = ((u_int32_t)bytes[0] << 24) |
+            ((u_int32_t)bytes[1] << 16) |
+            ((u_int32_t)bytes[2] << 8) |
+            (u_int32_t)bytes[3];
        return (rv);
 }
 
@@ -894,10 +894,10 @@
 {
        u_int32_t rv;
 
-       rv = bytes[0] |
-            (bytes[1] << 8) |
-            (bytes[2] << 16) |
-            (bytes[3] << 24);
+       rv = (u_int32_t)bytes[0] |
+            ((u_int32_t)bytes[1] << 8) |
+            ((u_int32_t)bytes[2] << 16) |
+            ((u_int32_t)bytes[3] << 24);
        return (rv);
 }
 



Home | Main Index | Thread Index | Old Index