All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] monitor: Fix warnings when using l2cap_frame_get*
Date: Mon,  1 Sep 2014 14:30:43 +0300	[thread overview]
Message-ID: <1409571044-24724-2-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1409571044-24724-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 monitor/avctp.c | 48 +++++++++++++++++++++---------------------------
 monitor/sdp.c   | 12 +++++-------
 2 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/monitor/avctp.c b/monitor/avctp.c
index 5543a49..64d4b58 100644
--- a/monitor/avctp.c
+++ b/monitor/avctp.c
@@ -512,15 +512,13 @@ static bool avrcp_get_capabilities(struct l2cap_frame *frame, uint8_t ctype,
 	switch (cap) {
 	case 0x2:
 		for (; count > 0; count--) {
-			uint8_t company[3] = {};
+			uint8_t company[3];
 
-			if (frame->size < 3)
+			if (!l2cap_frame_get_u8(frame, &company[0]) ||
+				!l2cap_frame_get_u8(frame, &company[1]) ||
+				!l2cap_frame_get_u8(frame, &company[2]))
 				return false;
 
-			l2cap_frame_get_u8(frame, &company[0]);
-			l2cap_frame_get_u8(frame, &company[1]);
-			l2cap_frame_get_u8(frame, &company[2]);
-
 			print_field("%*c%s: 0x%02x%02x%02x", (indent - 8), ' ',
 					cap2str(cap), company[0], company[1],
 					company[2]);
@@ -645,12 +643,14 @@ static bool avrcp_pdu_packet(struct l2cap_frame *frame, uint8_t ctype,
 	int i;
 	const struct avrcp_ctrl_pdu_data *ctrl_pdu_data = NULL;
 
-	if (frame->size < 4)
+	if (!l2cap_frame_get_u8(frame, &pduid))
+		return false;
+
+	if (!l2cap_frame_get_u8(frame, &pt))
 		return false;
 
-	l2cap_frame_get_u8(frame, &pduid);
-	l2cap_frame_get_u8(frame, &pt);
-	l2cap_frame_get_be16(frame, &len);
+	if (!l2cap_frame_get_be16(frame, &len))
+		return false;
 
 	print_indent(indent, COLOR_OFF, "AVRCP: ", pdu2str(pduid), COLOR_OFF,
 					" pt %s len 0x%04x", pt2str(pt), len);
@@ -680,13 +680,11 @@ static bool avrcp_control_packet(struct l2cap_frame *frame)
 {
 	uint8_t ctype, address, subunit, opcode, company[3], indent = 2;
 
-	if (frame->size < 3)
+	if (!l2cap_frame_get_u8(frame, &ctype) ||
+				!l2cap_frame_get_u8(frame, &address) ||
+				!l2cap_frame_get_u8(frame, &opcode))
 		return false;
 
-	l2cap_frame_get_u8(frame, &ctype);
-	l2cap_frame_get_u8(frame, &address);
-	l2cap_frame_get_u8(frame, &opcode);
-
 	print_field("AV/C: %s: address 0x%02x opcode 0x%02x",
 				ctype2str(ctype), address, opcode);
 
@@ -712,13 +710,11 @@ static bool avrcp_control_packet(struct l2cap_frame *frame)
 	case 0x7c:
 		return avrcp_passthrough_packet(frame);
 	case 0x00:
-		if (frame->size < 3)
+		if (!l2cap_frame_get_u8(frame, &company[0]) ||
+				!l2cap_frame_get_u8(frame, &company[1]) ||
+				!l2cap_frame_get_u8(frame, &company[2]))
 			return false;
 
-		l2cap_frame_get_u8(frame, &company[0]);
-		l2cap_frame_get_u8(frame, &company[1]);
-		l2cap_frame_get_u8(frame, &company[2]);
-
 		print_field("%*cCompany ID: 0x%02x%02x%02x", indent, ' ',
 					company[0], company[1], company[2]);
 
@@ -764,16 +760,14 @@ void avctp_packet(const struct l2cap_frame *frame)
 	struct l2cap_frame avctp_frame;
 	const char *pdu_color;
 
-	if (frame->size < 3) {
+	l2cap_frame_pull(&avctp_frame, frame, 0);
+
+	if (!l2cap_frame_get_u8(&avctp_frame, &hdr) ||
+				!l2cap_frame_get_be16(&avctp_frame, &pid)) {
 		print_text(COLOR_ERROR, "frame too short");
 		packet_hexdump(frame->data, frame->size);
 		return;
-        }
-
-	l2cap_frame_pull(&avctp_frame, frame, 0);
-
-	l2cap_frame_get_u8(&avctp_frame, &hdr);
-	l2cap_frame_get_be16(&avctp_frame, &pid);
+	}
 
 	if (frame->in)
 		pdu_color = COLOR_MAGENTA;
diff --git a/monitor/sdp.c b/monitor/sdp.c
index d0ad688..c171b9d 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -696,18 +696,16 @@ void sdp_packet(const struct l2cap_frame *frame)
 	const char *pdu_color, *pdu_str;
 	int i;
 
-	if (frame->size < 5) {
+	l2cap_frame_pull(&sdp_frame, frame, 0);
+
+	if (!l2cap_frame_get_u8(&sdp_frame, &pdu) ||
+				!l2cap_frame_get_be16(&sdp_frame, &tid) ||
+				!l2cap_frame_get_be16(&sdp_frame, &plen)) {
 		print_text(COLOR_ERROR, "frame too short");
 		packet_hexdump(frame->data, frame->size);
 		return;
 	}
 
-	l2cap_frame_pull(&sdp_frame, frame, 0);
-
-	l2cap_frame_get_u8(&sdp_frame, &pdu);
-	l2cap_frame_get_be16(&sdp_frame, &tid);
-	l2cap_frame_get_be16(&sdp_frame, &plen);
-
 	if (sdp_frame.size != plen) {
 		print_text(COLOR_ERROR, "invalid frame size");
 		packet_hexdump(sdp_frame.data, sdp_frame.size);
-- 
1.9.3


  reply	other threads:[~2014-09-01 11:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-01 11:30 [PATCH BlueZ 1/2] doc: Add initial documentation for coding style Luiz Augusto von Dentz
2014-09-01 11:30 ` Luiz Augusto von Dentz [this message]
2014-09-01 11:32   ` [PATCH BlueZ] monitor: Fix warnings when using l2cap_frame_get* Luiz Augusto von Dentz
2014-09-01 11:30 ` [PATCH BlueZ 2/2] build: Add initial HACKING Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2014-08-29 10:03 [PATCH BlueZ] monitor: Fix warnings when using l2cap_frame_get* Luiz Augusto von Dentz

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=1409571044-24724-2-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.