CVS commit: src/common/lib/libc/sys

2018-07-25 Thread Kamil Rytarowski
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;
 }
 



CVS commit: src/common/lib/libc/sys

2010-09-20 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Tue Sep 21 02:03:29 UTC 2010

Modified Files:
src/common/lib/libc/sys: cpuset.c

Log Message:
_cpuset_create: initialize size argument for sysctl call.
From PR/43837 by Sandy Snaman.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 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.15 src/common/lib/libc/sys/cpuset.c:1.16
--- src/common/lib/libc/sys/cpuset.c:1.15	Sat Apr 25 19:38:25 2009
+++ src/common/lib/libc/sys/cpuset.c	Tue Sep 21 02:03:29 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpuset.c,v 1.15 2009/04/25 19:38:25 rmind Exp $	*/
+/*	$NetBSD: cpuset.c,v 1.16 2010/09/21 02:03:29 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #ifndef _STANDALONE
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: cpuset.c,v 1.15 2009/04/25 19:38:25 rmind Exp $);
+__RCSID($NetBSD: cpuset.c,v 1.16 2010/09/21 02:03:29 rmind Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/param.h
@@ -144,6 +144,7 @@
 		size_t len;
 		u_int nc;
 
+		len = sizeof(nc);
 		if (sysctl(mib, __arraycount(mib), nc, len, NULL, 0) == -1)
 			return NULL;