Module Name:    src
Committed By:   jakllsch
Date:           Thu Jan  7 15:58:23 UTC 2016

Modified Files:
        src/tests/dev/usb: t_hid.c
        src/tests/lib/libusbhid: hid_test_data.c t_usbhid.c

Log Message:
Add tests for HID Parser Pop-on-empty-stack bug.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/dev/usb/t_hid.c
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libusbhid/hid_test_data.c
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libusbhid/t_usbhid.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/dev/usb/t_hid.c
diff -u src/tests/dev/usb/t_hid.c:1.1 src/tests/dev/usb/t_hid.c:1.2
--- src/tests/dev/usb/t_hid.c:1.1	Tue Jan  5 17:22:38 2016
+++ src/tests/dev/usb/t_hid.c	Thu Jan  7 15:58:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_hid.c,v 1.1 2016/01/05 17:22:38 jakllsch Exp $	*/
+/*	$NetBSD: t_hid.c,v 1.2 2016/01/07 15:58:23 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2016 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_hid.c,v 1.1 2016/01/05 17:22:38 jakllsch Exp $");
+__RCSID("$NetBSD: t_hid.c,v 1.2 2016/01/07 15:58:23 jakllsch Exp $");
 
 #include <machine/types.h>
 #include <stdlib.h>
@@ -200,10 +200,34 @@ ATF_TC_BODY(khid, tc)
 	    &hi.loc), 0xff);
 }
 
+ATF_TC(khid_parse_just_pop);
+
+ATF_TC_HEAD(khid_parse_just_pop, tc)
+{
+
+        atf_tc_set_md_var(tc, "descr", "check kernel hid.c for "
+	    "Pop on empty stack bug");
+}
+
+ATF_TC_BODY(khid_parse_just_pop, tc)
+{
+	struct hid_data *hdp;
+	struct hid_item hi;
+
+	atf_tc_expect_fail("Pop crashes on empty stack.");
+
+	hdp = hid_start_parse(just_pop_report_descriptor,
+	    sizeof just_pop_report_descriptor, hid_none);
+	while (hid_get_item(hdp, &hi) > 0) {
+	}
+	hid_end_parse(hdp);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
         ATF_TP_ADD_TC(tp, khid);
+        ATF_TP_ADD_TC(tp, khid_parse_just_pop);
 
 	return atf_no_error();
 }

Index: src/tests/lib/libusbhid/hid_test_data.c
diff -u src/tests/lib/libusbhid/hid_test_data.c:1.1 src/tests/lib/libusbhid/hid_test_data.c:1.2
--- src/tests/lib/libusbhid/hid_test_data.c:1.1	Mon Jan  4 22:07:16 2016
+++ src/tests/lib/libusbhid/hid_test_data.c	Thu Jan  7 15:58:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: hid_test_data.c,v 1.1 2016/01/04 22:07:16 jakllsch Exp $	*/
+/*	$NetBSD: hid_test_data.c,v 1.2 2016/01/07 15:58:23 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2016 Jonathan A. Kollasch
@@ -132,3 +132,6 @@ static const uint8_t unsigned_range_test
 	0xff,
 };
 
+static const uint8_t just_pop_report_descriptor[] = {
+	0xb4,
+};

Index: src/tests/lib/libusbhid/t_usbhid.c
diff -u src/tests/lib/libusbhid/t_usbhid.c:1.9 src/tests/lib/libusbhid/t_usbhid.c:1.10
--- src/tests/lib/libusbhid/t_usbhid.c:1.9	Mon Jan  4 22:07:16 2016
+++ src/tests/lib/libusbhid/t_usbhid.c	Thu Jan  7 15:58:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_usbhid.c,v 1.9 2016/01/04 22:07:16 jakllsch Exp $	*/
+/*	$NetBSD: t_usbhid.c,v 1.10 2016/01/07 15:58:23 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2016 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_usbhid.c,v 1.9 2016/01/04 22:07:16 jakllsch Exp $");
+__RCSID("$NetBSD: t_usbhid.c,v 1.10 2016/01/07 15:58:23 jakllsch Exp $");
 
 #include <atf-c.h>
 
@@ -45,6 +45,7 @@ ATF_TC(check_hid_physical_range);
 ATF_TC(check_hid_usage);
 ATF_TC(check_hid_get_data);
 ATF_TC(check_hid_set_data);
+ATF_TC(check_parse_just_pop);
 
 #define MYd_ATF_CHECK_EQ(d, v) \
 	ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
@@ -411,6 +412,31 @@ ATF_TC_BODY(check_hid_set_data, tc)
 	hrd = NULL;
 }
 
+ATF_TC_HEAD(check_parse_just_pop, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "check Pop on empty stack bug");
+}
+
+ATF_TC_BODY(check_parse_just_pop, tc)
+{
+	report_desc_t hrd;
+	hid_data_t hd;
+	hid_item_t hi;
+
+	atf_tc_expect_fail("segfaults");
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    just_pop_report_descriptor,
+	    sizeof just_pop_report_descriptor)) != NULL);
+	hd = hid_start_parse(hrd, 0, NO_REPORT_ID);
+	while (hid_get_item(hd, &hi) > 0) {
+	}
+	hid_end_parse(hd);
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -419,6 +445,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, check_hid_usage);
 	ATF_TP_ADD_TC(tp, check_hid_get_data);
 	ATF_TP_ADD_TC(tp, check_hid_set_data);
+	ATF_TP_ADD_TC(tp, check_parse_just_pop);
 
 	return atf_no_error();
 }

Reply via email to