From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Anderson Lizardo <anderson.lizardo@openbossa.org>
Subject: [PATCH 3/3] Modify dec_read_req() to get PDU length as parameter
Date: Mon, 4 Oct 2010 14:54:42 -0400 [thread overview]
Message-ID: <1286218482-972-3-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1286218482-972-1-git-send-email-anderson.lizardo@openbossa.org>
This is consistent with other att.h functions, and allows length checks.
---
attrib/att.c | 5 ++++-
attrib/att.h | 2 +-
src/attrib-server.c | 2 +-
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/attrib/att.c b/attrib/att.c
index a795ddd..fc87d98 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -379,7 +379,7 @@ uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len)
return min_len;
}
-uint16_t dec_read_req(const uint8_t *pdu, uint16_t *handle)
+uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle)
{
const uint16_t min_len = sizeof(pdu[0]) + sizeof(*handle);
@@ -389,6 +389,9 @@ uint16_t dec_read_req(const uint8_t *pdu, uint16_t *handle)
if (handle == NULL)
return 0;
+ if (len < min_len)
+ return 0;
+
if (pdu[0] != ATT_OP_READ_REQ)
return 0;
diff --git a/attrib/att.h b/attrib/att.h
index 69071b4..89fc52d 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -179,7 +179,7 @@ uint16_t dec_write_cmd(const uint8_t *pdu, int len, uint16_t *handle,
uint8_t *value, int *vlen);
struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, int len);
uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, int len);
-uint16_t dec_read_req(const uint8_t *pdu, uint16_t *handle);
+uint16_t dec_read_req(const uint8_t *pdu, int len, uint16_t *handle);
uint16_t enc_read_resp(uint8_t *value, int vlen, uint8_t *pdu, int len);
uint16_t dec_read_resp(const uint8_t *pdu, int len, uint8_t *value, int *vlen);
uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status,
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 475b68b..b45f300 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -478,7 +478,7 @@ static void channel_handler(const uint8_t *ipdu, uint16_t len,
length = read_by_type(start, end, &uuid, opdu, channel->mtu);
break;
case ATT_OP_READ_REQ:
- length = dec_read_req(ipdu, &start);
+ length = dec_read_req(ipdu, len, &start);
if (length == 0) {
status = ATT_ECODE_INVALID_PDU;
goto done;
--
1.7.0.4
prev parent reply other threads:[~2010-10-04 18:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-04 18:54 [PATCH 1/3] Remove typecast from att_get_u16() calls Anderson Lizardo
2010-10-04 18:54 ` [PATCH 2/3] Replace hardcoded minimum length values with constants Anderson Lizardo
2010-10-04 18:54 ` Anderson Lizardo [this message]
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=1286218482-972-3-git-send-email-anderson.lizardo@openbossa.org \
--to=anderson.lizardo@openbossa.org \
--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