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_is...



details:   https://anonhg.NetBSD.org/src/rev/7d89993e4fbe
branches:  trunk
changeset: 362967:7d89993e4fbe
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Jul 03 22:49:51 2018 +0000

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

Detected with Kernel Undefined Behavior Sanitizer.

sys/kern/kern_descrip.c:188:34, left shift of 1 by 31 places cannot be represented in type 'int'

Reported by <Harry Pantazis>

diffstat:

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

diffs (27 lines):

diff -r 496a40818256 -r 7d89993e4fbe sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Tue Jul 03 22:38:33 2018 +0000
+++ b/sys/kern/kern_descrip.c   Tue Jul 03 22:49:51 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.232 2018/07/03 12:17:54 kamil Exp $ */
+/*     $NetBSD: kern_descrip.c,v 1.233 2018/07/03 22:49:51 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.232 2018/07/03 12:17:54 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.233 2018/07/03 22:49:51 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -185,7 +185,7 @@
 
        KASSERT(fd < fdp->fd_dt->dt_nfiles);
 
-       return (fdp->fd_lomap[off] & (1 << (fd & NDENTRYMASK))) != 0;
+       return (fdp->fd_lomap[off] & (1U << (fd & NDENTRYMASK))) != 0;
 }
 
 /*



Home | Main Index | Thread Index | Old Index