Module Name: src
Committed By: skrll
Date: Fri Mar 31 10:13:09 UTC 2017
Modified Files:
src/sys/dev/usb [netbsd-7-nhusb]: ukbd.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.129.4.1.4.2 -r1.129.4.1.4.3 src/sys/dev/usb/ukbd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/ukbd.c
diff -u src/sys/dev/usb/ukbd.c:1.129.4.1.4.2 src/sys/dev/usb/ukbd.c:1.129.4.1.4.3
--- src/sys/dev/usb/ukbd.c:1.129.4.1.4.2 Thu Jan 26 21:54:24 2017
+++ src/sys/dev/usb/ukbd.c Fri Mar 31 10:13:09 2017
@@ -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 @@ ukbd_decode(struct ukbd_softc *sc, struc
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 @@ ukbd_cngetc(void *v, u_int *type, int *d
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;