Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netbt cleanup some DIAGNOSTIC and KASSERT code
details: https://anonhg.NetBSD.org/src/rev/ede2fec4452a
branches: trunk
changeset: 767683:ede2fec4452a
user: plunky <plunky%NetBSD.org@localhost>
date: Wed Jul 27 10:25:09 2011 +0000
description:
cleanup some DIAGNOSTIC and KASSERT code
- remove #ifdef DIAGNOSTIC, so that we won't act
differently
- handle the cases where a Bluetooth adapter
sends invalid packet data (I've not seen this,
but it is not impossible)
- use KASSERT for actual impossible situations
(to catch bad future development)
diffstat:
sys/netbt/hci_event.c | 102 +++++++++++++++++++++++++++++++++-----------
sys/netbt/hci_link.c | 55 ++++++++---------------
sys/netbt/l2cap_signal.c | 17 +-----
sys/netbt/rfcomm_session.c | 7 +-
4 files changed, 102 insertions(+), 79 deletions(-)
diffs (truncated from 487 to 300 lines):
diff -r 19e9ae38c986 -r ede2fec4452a sys/netbt/hci_event.c
--- a/sys/netbt/hci_event.c Wed Jul 27 05:04:11 2011 +0000
+++ b/sys/netbt/hci_event.c Wed Jul 27 10:25:09 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hci_event.c,v 1.22 2010/11/22 19:56:51 plunky Exp $ */
+/* $NetBSD: hci_event.c,v 1.23 2011/07/27 10:25:09 plunky Exp $ */
/*-
* Copyright (c) 2005 Iain Hibbert.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hci_event.c,v 1.22 2010/11/22 19:56:51 plunky Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hci_event.c,v 1.23 2011/07/27 10:25:09 plunky Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -157,8 +157,7 @@
* process HCI Events
*
* We will free the mbuf at the end, no need for any sub
- * functions to handle that. We kind of assume that the
- * device sends us valid events.
+ * functions to handle that.
*/
void
hci_event(struct mbuf *m, struct hci_unit *unit)
@@ -167,11 +166,15 @@
KASSERT(m->m_flags & M_PKTHDR);
- KASSERT(m->m_pkthdr.len >= sizeof(hdr));
+ if (m->m_pkthdr.len < sizeof(hdr))
+ goto done;
+
m_copydata(m, 0, sizeof(hdr), &hdr);
m_adj(m, sizeof(hdr));
KASSERT(hdr.type == HCI_EVENT_PKT);
+ if (m->m_pkthdr.len != hdr.length)
+ goto done;
DPRINTFN(1, "(%s) event %s\n",
device_xname(unit->hci_dev), hci_eventstr(hdr.event));
@@ -233,6 +236,7 @@
break;
}
+done:
m_freem(m);
}
@@ -246,7 +250,9 @@
{
hci_command_status_ep ep;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -292,7 +298,9 @@
hci_command_compl_ep ep;
hci_status_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -369,7 +377,9 @@
uint16_t handle, num;
int num_acl = 0, num_sco = 0;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -439,7 +449,9 @@
hci_inquiry_response ir;
struct hci_memo *memo;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -447,7 +459,9 @@
(ep.num_responses == 1 ? "" : "s"));
while(ep.num_responses--) {
- KASSERT(m->m_pkthdr.len >= sizeof(ir));
+ if (m->m_pkthdr.len < sizeof(ir))
+ return;
+
m_copydata(m, 0, sizeof(ir), &ir);
m_adj(m, sizeof(ir));
@@ -476,7 +490,9 @@
hci_rssi_response rr;
struct hci_memo *memo;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -484,7 +500,9 @@
(ep.num_responses == 1 ? "" : "s"));
while(ep.num_responses--) {
- KASSERT(m->m_pkthdr.len >= sizeof(rr));
+ if (m->m_pkthdr.len < sizeof(rr))
+ return;
+
m_copydata(m, 0, sizeof(rr), &rr);
m_adj(m, sizeof(rr));
@@ -512,7 +530,9 @@
hci_extended_result_ep ep;
struct hci_memo *memo;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -546,7 +566,9 @@
struct hci_link *link;
int err;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -641,7 +663,9 @@
hci_discon_compl_ep ep;
struct hci_link *link;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -668,7 +692,9 @@
hci_reject_con_cp rp;
struct hci_link *link;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -715,7 +741,9 @@
struct hci_link *link;
int err;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -757,7 +785,9 @@
struct hci_link *link;
int err;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -801,7 +831,9 @@
struct hci_link *link;
int err;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -841,7 +873,9 @@
hci_read_clock_offset_compl_ep ep;
struct hci_link *link;
- KASSERT(m->m_pkthdr.len >= sizeof(ep));
+ if (m->m_pkthdr.len < sizeof(ep))
+ return;
+
m_copydata(m, 0, sizeof(ep), &ep);
m_adj(m, sizeof(ep));
@@ -865,7 +899,9 @@
{
hci_read_bdaddr_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
@@ -890,7 +926,9 @@
{
hci_read_buffer_size_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
@@ -920,7 +958,9 @@
{
hci_read_local_features_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
@@ -1029,7 +1069,9 @@
{
hci_read_local_extended_features_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
@@ -1076,7 +1118,9 @@
{
hci_read_local_ver_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
@@ -1103,7 +1147,9 @@
{
hci_read_local_commands_rp rp;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
@@ -1132,7 +1178,9 @@
struct hci_link *link, *next;
int acl;
- KASSERT(m->m_pkthdr.len >= sizeof(rp));
+ if (m->m_pkthdr.len < sizeof(rp))
+ return;
+
m_copydata(m, 0, sizeof(rp), &rp);
m_adj(m, sizeof(rp));
diff -r 19e9ae38c986 -r ede2fec4452a sys/netbt/hci_link.c
--- a/sys/netbt/hci_link.c Wed Jul 27 05:04:11 2011 +0000
+++ b/sys/netbt/hci_link.c Wed Jul 27 10:25:09 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hci_link.c,v 1.22 2010/10/14 07:05:03 plunky Exp $ */
Home |
Main Index |
Thread Index |
Old Index