Module Name:src
Committed By: kamil
Date: Thu Jul 26 00:13:19 UTC 2018
Modified Files:
src/common/lib/libc/sys: cpuset.c
Log Message:
Avoid undefined behavior in an cpuset.c
Do not change the signedness bit with a left shift operation.
Switch to unsigned integer to prevent this.
cpuset.c:112:18, left shift of 1 by 31 places cannot be represented in type
'int'
Detected with micro-UBSan in the user mode.
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/common/lib/libc/sys/cpuset.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/sys/cpuset.c
diff -u src/common/lib/libc/sys/cpuset.c:1.19 src/common/lib/libc/sys/cpuset.c:1.20
--- src/common/lib/libc/sys/cpuset.c:1.19 Thu Jan 4 20:57:28 2018
+++ src/common/lib/libc/sys/cpuset.c Thu Jul 26 00:13:19 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuset.c,v 1.19 2018/01/04 20:57:28 kamil Exp $ */
+/* $NetBSD: cpuset.c,v 1.20 2018/07/26 00:13:19 kamil Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#ifndef _STANDALONE
#include
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: cpuset.c,v 1.19 2018/01/04 20:57:28 kamil Exp $");
+__RCSID("$NetBSD: cpuset.c,v 1.20 2018/07/26 00:13:19 kamil Exp $");
#endif /* LIBC_SCCS and not lint */
#ifdef _LIBC
@@ -97,7 +97,7 @@ _cpuset_isset(cpuid_t i, const cpuset_t
errno = EINVAL;
return -1;
}
- return ((1 << (unsigned int)(i & CPUSET_MASK)) & c->bits[j]) != 0;
+ return ((1U << (unsigned int)(i & CPUSET_MASK)) & c->bits[j]) != 0;
}
int
@@ -109,7 +109,7 @@ _cpuset_set(cpuid_t i, cpuset_t *c)
errno = EINVAL;
return -1;
}
- c->bits[j] |= 1 << (unsigned int)(i & CPUSET_MASK);
+ c->bits[j] |= 1U << (unsigned int)(i & CPUSET_MASK);
return 0;
}
@@ -122,7 +122,7 @@ _cpuset_clr(cpuid_t i, cpuset_t *c)
errno = EINVAL;
return -1;
}
- c->bits[j] &= ~(1 << (unsigned int)(i & CPUSET_MASK));
+ c->bits[j] &= ~(1U << (unsigned int)(i & CPUSET_MASK));
return 0;
}