Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-7-nhusb]: src/sys/dev/usb revision 1.136



details:   https://anonhg.NetBSD.org/src/rev/29c28adb4326
branches:  netbsd-7-nhusb
changeset: 801046:29c28adb4326
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Mar 31 10:13:09 2017 +0000

description:
revision 1.136
don't memcpy overlapping buffers, use memmove.
this is undefined behaviour.
CID 1299069
----------------------------
revision 1.135
kassert that we aren't overflowing the array.

this assert isn't expected to trigger due to current parameters used, but
to be sure, check.

diffstat:

 sys/dev/usb/ukbd.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (39 lines):

diff -r 9ab616b826b5 -r 29c28adb4326 sys/dev/usb/ukbd.c
--- a/sys/dev/usb/ukbd.c        Fri Mar 31 10:05:07 2017 +0000
+++ b/sys/dev/usb/ukbd.c        Fri Mar 31 10:13:09 2017 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ukbd.c,v 1.129.4.1.4.2 2017/01/26 21:54:24 skrll Exp $        */
+/*      $NetBSD: ukbd.c,v 1.129.4.1.4.3 2017/03/31 10:13:09 skrll Exp $        */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.129.4.1.4.2 2017/01/26 21:54:24 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.129.4.1.4.3 2017/03/31 10:13:09 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -719,7 +719,10 @@
        int s;
        int nkeys, i, j;
        int key;
-#define ADDKEY(c) ibuf[nkeys++] = (c)
+#define ADDKEY(c) do { \
+    KASSERT(nkeys < MAXKEYS); \
+    ibuf[nkeys++] = (c); \
+} while (0)
 
 #ifdef UKBD_DEBUG
        /*
@@ -1001,7 +1004,7 @@
        sc->sc_flags &= ~FLAG_POLLING;
        c = sc->sc_pollchars[0];
        sc->sc_npollchar--;
-       memcpy(sc->sc_pollchars, sc->sc_pollchars+1,
+       memmove(sc->sc_pollchars, sc->sc_pollchars+1,
               sc->sc_npollchar * sizeof(uint16_t));
        *type = c & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
        *data = c & CODEMASK;



Home | Main Index | Thread Index | Old Index