summaryrefslogtreecommitdiff
path: root/lib/libusbhid
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2010-10-16 11:20:53 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2010-10-16 11:20:53 +0000
commit951acbc0ff23d6cf6eaacb2c7eaeaa54f0f7c601 (patch)
tree1ea0271ac1ee85fd4578cf84cc88d1e6186f7224 /lib/libusbhid
parent2b89f1fc9e8b71154dba0bc5852a24751e411f5e (diff)
downloadsrc-test2-951acbc0ff23d6cf6eaacb2c7eaeaa54f0f7c601.tar.gz
src-test2-951acbc0ff23d6cf6eaacb2c7eaeaa54f0f7c601.zip
Notes
Diffstat (limited to 'lib/libusbhid')
-rw-r--r--lib/libusbhid/Makefile4
-rw-r--r--lib/libusbhid/descr.c13
-rw-r--r--lib/libusbhid/usbvar.h11
3 files changed, 25 insertions, 3 deletions
diff --git a/lib/libusbhid/Makefile b/lib/libusbhid/Makefile
index 2a58a4b1eb48..7dba7ffc9113 100644
--- a/lib/libusbhid/Makefile
+++ b/lib/libusbhid/Makefile
@@ -19,4 +19,8 @@ SRCS= descr.c descr_compat.c parse.c usage.c data.c
INCS= usbhid.h
+.if defined(COMPAT_32BIT)
+CFLAGS+= -DCOMPAT_32BIT
+.endif
+
.include <bsd.lib.mk>
diff --git a/lib/libusbhid/descr.c b/lib/libusbhid/descr.c
index a5c033abfdcb..def90da3b794 100644
--- a/lib/libusbhid/descr.c
+++ b/lib/libusbhid/descr.c
@@ -103,7 +103,7 @@ hid_get_report_desc(int fd)
memset(&ugd, 0, sizeof(ugd));
/* get actual length first */
- ugd.ugd_data = NULL;
+ ugd.ugd_data = hid_pass_ptr(NULL);
ugd.ugd_maxlen = 65535;
if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) {
#ifdef HID_COMPAT7
@@ -124,7 +124,7 @@ hid_get_report_desc(int fd)
return (NULL);
/* fetch actual descriptor */
- ugd.ugd_data = data;
+ ugd.ugd_data = hid_pass_ptr(data);
ugd.ugd_maxlen = ugd.ugd_actlen;
if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) {
/* could not read descriptor */
@@ -132,8 +132,15 @@ hid_get_report_desc(int fd)
return (NULL);
}
+ /* sanity check */
+ if (ugd.ugd_actlen < 1) {
+ /* invalid report descriptor */
+ free(data);
+ return (NULL);
+ }
+
/* check END_COLLECTION */
- if (((unsigned char *)ugd.ugd_data)[ugd.ugd_actlen -1] != 0xC0) {
+ if (((unsigned char *)data)[ugd.ugd_actlen -1] != 0xC0) {
/* invalid end byte */
free(data);
return (NULL);
diff --git a/lib/libusbhid/usbvar.h b/lib/libusbhid/usbvar.h
index 96051061a73b..2722a3783fac 100644
--- a/lib/libusbhid/usbvar.h
+++ b/lib/libusbhid/usbvar.h
@@ -29,6 +29,9 @@
*
*/
+#ifndef _USBVAR_H_
+#define _USBVAR_H_
+
struct report_desc {
uint32_t size;
uint8_t data[1];
@@ -41,3 +44,11 @@ int hid_set_immed_compat7(int fd, int enable);
int hid_get_report_id_compat7(int fd);
report_desc_t hid_get_report_desc_compat7(int fd);
#endif
+
+#ifdef COMPAT_32BIT
+#define hid_pass_ptr(ptr) ((uint64_t)(uintptr_t)(ptr))
+#else
+#define hid_pass_ptr(ptr) (ptr)
+#endif
+
+#endif /* _USBVAR_H_ */