Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Avoid unportable signed integer left shift in fd_co...



details:   https://anonhg.NetBSD.org/src/rev/a1fcbf009ed0
branches:  trunk
changeset: 320385:a1fcbf009ed0
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Jul 03 23:11:06 2018 +0000

description:
Avoid unportable signed integer left shift in fd_copy()

Detected with Kernel Undefined Behavior Sanitizer.

There were at least a single place reported, for consistency fix all the
left bit shift operations.
sys/kern/kern_descrip.c:1492:3, left shift of 1 by 31 places cannot be represented in type 'int'
sys/kern/kern_descrip.c:1493:28, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>

diffstat:

 sys/kern/kern_descrip.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (36 lines):

diff -r 2f68610b02ec -r a1fcbf009ed0 sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Tue Jul 03 22:49:51 2018 +0000
+++ b/sys/kern/kern_descrip.c   Tue Jul 03 23:11:06 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.233 2018/07/03 22:49:51 kamil Exp $ */
+/*     $NetBSD: kern_descrip.c,v 1.234 2018/07/03 23:11:06 kamil Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.233 2018/07/03 22:49:51 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.234 2018/07/03 23:11:06 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1489,13 +1489,13 @@
 
                /* Fix up bitmaps. */
                j = i >> NDENTRYSHIFT;
-               KASSERT((newfdp->fd_lomap[j] & (1 << (i & NDENTRYMASK))) == 0);
-               newfdp->fd_lomap[j] |= 1 << (i & NDENTRYMASK);
+               KASSERT((newfdp->fd_lomap[j] & (1U << (i & NDENTRYMASK))) == 0);
+               newfdp->fd_lomap[j] |= 1U << (i & NDENTRYMASK);
                if (__predict_false(newfdp->fd_lomap[j] == ~0)) {
                        KASSERT((newfdp->fd_himap[j >> NDENTRYSHIFT] &
-                           (1 << (j & NDENTRYMASK))) == 0);
+                           (1U << (j & NDENTRYMASK))) == 0);
                        newfdp->fd_himap[j >> NDENTRYSHIFT] |=
-                           1 << (j & NDENTRYMASK);
+                           1U << (j & NDENTRYMASK);
                }
                newlast = i;
        }



Home | Main Index | Thread Index | Old Index