Module Name: src
Committed By: kamil
Date: Thu Jul 26 00:33:26 UTC 2018
Modified Files:
src/common/lib/libutil: snprintb.c
Log Message:
Avoid undefined behavior in snprintb.c
Do not change the signedness bit with a left shift operation.
Switch to unsigned integer to prevent this.
snprintb.c:178:17, 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.17 -r1.18 src/common/lib/libutil/snprintb.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/libutil/snprintb.c
diff -u src/common/lib/libutil/snprintb.c:1.17 src/common/lib/libutil/snprintb.c:1.18
--- src/common/lib/libutil/snprintb.c:1.17 Sat Oct 14 18:41:41 2017
+++ src/common/lib/libutil/snprintb.c Thu Jul 26 00:33:26 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: snprintb.c,v 1.17 2017/10/14 18:41:41 ryo Exp $ */
+/* $NetBSD: snprintb.c,v 1.18 2018/07/26 00:33:26 kamil Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
# include <sys/cdefs.h>
# if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: snprintb.c,v 1.17 2017/10/14 18:41:41 ryo Exp $");
+__RCSID("$NetBSD: snprintb.c,v 1.18 2018/07/26 00:33:26 kamil Exp $");
# endif
# include <sys/types.h>
@@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.17 2017
# include <errno.h>
# else /* ! _KERNEL */
# include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.17 2017/10/14 18:41:41 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.18 2018/07/26 00:33:26 kamil Exp $");
# include <sys/param.h>
# include <sys/inttypes.h>
# include <sys/systm.h>
@@ -175,7 +175,7 @@ snprintb_m(char *buf, size_t buflen, con
/* old (standard) format. */
for (;(bit = *bitfmt) != 0;) {
cur_fmt = bitfmt++;
- if (val & (1 << (bit - 1))) {
+ if (val & (1U << (bit - 1))) {
PUTSEP;
if (restart)
continue;