linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Johan Hedberg <johan.hedberg@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: [RFC] Bluetooth: don't increment twice in eir_has_data_type()
Date: Tue, 20 Mar 2012 18:06:11 +0300	[thread overview]
Message-ID: <20120320150611.GA24873@elgon.mountain> (raw)

I don't have this hardware, and I'm not familiar with this code.  It
just looked suspicious that we move the parsed counter forward faster
than the data pointer.  We do it once in middle the loop and again as
the for loop incrementer.  The effect is that we only search half the
data_len before returning false.

Also I've changed the breaks to just return false directly because it
made the code easier to follow.

I wrote this patch based on a guess of what the data might look like so
it's very likely wrong.  Could you maybe treat it as a bug report and
give me a Reported-by?

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8dc07fa..ff79f41 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -912,22 +912,17 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
 static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
 {
 	u8 field_len;
-	size_t parsed;
+	size_t parsed = 0;
 
-	for (parsed = 0; parsed < data_len - 1; parsed += field_len) {
+	while (parsed < data_len - 1) {
 		field_len = data[0];
 
 		if (field_len == 0)
-			break;
-
-		parsed += field_len + 1;
-
-		if (parsed > data_len)
-			break;
-
+			return false;
 		if (data[1] == type)
 			return true;
 
+		parsed += field_len + 1;
 		data += field_len + 1;
 	}
 

             reply	other threads:[~2012-03-20 15:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-20 15:06 Dan Carpenter [this message]
2012-03-21 22:06 ` [RFC] Bluetooth: don't increment twice in eir_has_data_type() Johan Hedberg
2012-03-22  6:28   ` Dan Carpenter
2012-03-26 11:30     ` Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120320150611.GA24873@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).