From 4581cca75c7231ffc81df0a35c25eb677c5257d3 Mon Sep 17 00:00:00 2001 From: kamil Date: Thu, 26 Jul 2018 00:13:19 +0000 Subject: [PATCH] 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. --- common/lib/libc/sys/cpuset.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common/lib/libc/sys/cpuset.c b/common/lib/libc/sys/cpuset.c index 8de431444774..2f374268812b 100644 --- a/common/lib/libc/sys/cpuset.c +++ b/common/lib/libc/sys/cpuset.c @@ -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 *c) 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; }