Module Name: src
Committed By: mlelstv
Date: Sun Jan 28 15:00:42 UTC 2018
Modified Files:
src/sys/arch/x86/x86: cpu_topology.c
Log Message:
Check for undefined behaviour when doing right-shift.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/x86/x86/cpu_topology.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/x86/cpu_topology.c
diff -u src/sys/arch/x86/x86/cpu_topology.c:1.10 src/sys/arch/x86/x86/cpu_topology.c:1.11
--- src/sys/arch/x86/x86/cpu_topology.c:1.10 Thu Sep 7 06:40:42 2017
+++ src/sys/arch/x86/x86/cpu_topology.c Sun Jan 28 15:00:42 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_topology.c,v 1.10 2017/09/07 06:40:42 msaitoh Exp $ */
+/* $NetBSD: cpu_topology.c,v 1.11 2018/01/28 15:00:42 mlelstv Exp $ */
/*-
* Copyright (c) 2009 Mindaugas Rasiukevicius <rmind at NetBSD org>,
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.10 2017/09/07 06:40:42 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.11 2018/01/28 15:00:42 mlelstv Exp $");
#include <sys/param.h>
#include <sys/bitops.h>
@@ -151,7 +151,10 @@ x86_cpu_topology(struct cpu_info *ci)
}
if (smt_bits + core_bits) {
- ci->ci_package_id = apic_id >> (smt_bits + core_bits);
+ if (smt_bits + core_bits < sizeof(apic_id) * NBBY)
+ ci->ci_package_id = apic_id >> (smt_bits + core_bits);
+ else
+ ci->ci_package_id = 0;
}
if (core_bits) {
u_int core_mask = __BITS(smt_bits, smt_bits + core_bits - 1);