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/d350f893e3aa
branches: trunk
changeset: 320393:d350f893e3aa
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 503e3fab99e6 -r d350f893e3aa 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