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/dd89b56d9510
branches:  trunk
changeset: 850469:dd89b56d9510
user:      fox <fox%NetBSD.org@localhost>
date:      Sat Apr 04 21:26:16 2020 +0000

description:
lib/libusbhid: Fix possible left shift changes signedness bit.

This bug was reported by UBSan runs.

lib/libusbhid/parse.c:246:20

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/parse.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 12daf40469d0 -r dd89b56d9510 lib/libusbhid/parse.c
--- a/lib/libusbhid/parse.c     Sat Apr 04 21:23:04 2020 +0000
+++ b/lib/libusbhid/parse.c     Sat Apr 04 21:26:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.10 2017/12/10 20:38:14 bouyer Exp $        */
+/*     $NetBSD: parse.c,v 1.11 2020/04/04 21:26:16 fox Exp $   */
 
 /*
  * Copyright (c) 1999, 2001 Lennart Augustsson <augustss%NetBSD.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: parse.c,v 1.10 2017/12/10 20:38:14 bouyer Exp $");
+__RCSID("$NetBSD: parse.c,v 1.11 2020/04/04 21:26:16 fox Exp $");
 
 #include <assert.h>
 #include <stdlib.h>
@@ -243,7 +243,7 @@
                        dval = *data++;
                        dval |= *data++ << 8;
                        dval |= *data++ << 16;
-                       dval |= *data++ << 24;
+                       dval |= ((uint32_t)*data++) << 24;
                        break;
                default:
                        return (-1);



Home | Main Index | Thread Index | Old Index