Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs/ffs Avoid Undefined Behavior in ffs_clusteracct()
details: https://anonhg.NetBSD.org/src/rev/4b8e0bcc607a
branches: trunk
changeset: 991247:4b8e0bcc607a
user: kamil <kamil%NetBSD.org@localhost>
date: Wed Jul 04 02:02:15 2018 +0000
description:
Avoid Undefined Behavior in ffs_clusteracct()
Change the type of 'bit' variable from int to unsigned int and use unsigned
values consistently.
sys/ufs/ffs/ffs_subr.c:336:10, shift exponent -1 is negative
Detected with Kernel Undefined Behavior Sanitizer.
Reported by <Harry Pantazis>
diffstat:
sys/ufs/ffs/ffs_subr.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diffs (55 lines):
diff -r e628e418962a -r 4b8e0bcc607a sys/ufs/ffs/ffs_subr.c
--- a/sys/ufs/ffs/ffs_subr.c Wed Jul 04 01:42:37 2018 +0000
+++ b/sys/ufs/ffs/ffs_subr.c Wed Jul 04 02:02:15 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $ */
+/* $NetBSD: ffs_subr.c,v 1.50 2018/07/04 02:02:15 kamil Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -36,7 +36,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.49 2016/05/07 11:59:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.50 2018/07/04 02:02:15 kamil Exp $");
#include <sys/param.h>
@@ -287,7 +287,8 @@
int32_t *sump;
int32_t *lp;
u_char *freemapp, *mapp;
- int i, start, end, forw, back, map, bit;
+ int i, start, end, forw, back, map;
+ unsigned int bit;
const int needswap = UFS_FSNEEDSWAP(fs);
/* KASSERT(mutex_owned(&ump->um_lock)); */
@@ -312,7 +313,7 @@
end = ufs_rw32(cgp->cg_nclusterblks, needswap);
mapp = &freemapp[start / NBBY];
map = *mapp++;
- bit = 1 << (start % NBBY);
+ bit = 1U << (start % NBBY);
for (i = start; i < end; i++) {
if ((map & bit) == 0)
break;
@@ -333,7 +334,7 @@
end = -1;
mapp = &freemapp[start / NBBY];
map = *mapp--;
- bit = 1 << (start % NBBY);
+ bit = 1U << (start % NBBY);
for (i = start; i > end; i--) {
if ((map & bit) == 0)
break;
@@ -341,7 +342,7 @@
bit >>= 1;
} else {
map = *mapp--;
- bit = 1 << (NBBY - 1);
+ bit = 1U << (NBBY - 1);
}
}
back = start - i;
Home |
Main Index |
Thread Index |
Old Index