Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libusbhid lib/libusbhid: Fix possible left shift changes...
details: https://anonhg.NetBSD.org/src/rev/1ba5e74190d6
branches: trunk
changeset: 970847:1ba5e74190d6
user: fox <fox%NetBSD.org@localhost>
date: Sat Apr 04 21:23:04 2020 +0000
description:
lib/libusbhid: Fix possible left shift changes signedness bit.
This bug was reported by UBSan runs.
lib/libusbhid/usage.c:247:27
lib/libusbhid/usage.c:244:28
lib/libusbhid/usage.c:235:13
Can result in left shift changes signedness bit as a side effect positive number
can go negative, cast it to unsigned for the operation and silence the issue.
Reviewed by: kamil@
diffstat:
lib/libusbhid/usage.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diffs (39 lines):
diff -r d835d39bffa3 -r 1ba5e74190d6 lib/libusbhid/usage.c
--- a/lib/libusbhid/usage.c Sat Apr 04 21:21:35 2020 +0000
+++ b/lib/libusbhid/usage.c Sat Apr 04 21:23:04 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usage.c,v 1.10 2016/01/02 21:58:10 christos Exp $ */
+/* $NetBSD: usage.c,v 1.11 2020/04/04 21:23:04 fox Exp $ */
/*
* Copyright (c) 1999 Lennart Augustsson <augustss%NetBSD.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: usage.c,v 1.10 2016/01/02 21:58:10 christos Exp $");
+__RCSID("$NetBSD: usage.c,v 1.11 2020/04/04 21:23:04 fox Exp $");
#include <assert.h>
#include <ctype.h>
@@ -232,7 +232,7 @@
if (strncmp(pages[k].name, name, len) == 0)
goto found;
if (sscanf(name, "%x:%x", &k, &j) == 2) {
- return (k << 16) | j;
+ return (((uint32_t)k) << 16) | j;
}
return -1;
found:
@@ -241,9 +241,9 @@
if (pages[k].page_contents[j].usage == -1) {
if (sscanf(sep, fmtcheck(
pages[k].page_contents[j].name, "%u"), &l) == 1) {
- return (pages[k].usage << 16) | l;
+ return (((uint32_t)pages[k].usage) << 16) | l;
}
} else if (strcmp(pages[k].page_contents[j].name, sep) == 0)
- return (pages[k].usage << 16) | pages[k].page_contents[j].usage;
+ return (((uint32_t)pages[k].usage) << 16) | pages[k].page_contents[j].usage;
return (-1);
}
Home |
Main Index |
Thread Index |
Old Index