summaryrefslogtreecommitdiff
path: root/attrib
diff options
context:
space:
mode:
authorAnderson Lizardo <anderson.lizardo@openbossa.org>2014-01-11 00:47:27 -0400
committerJohan Hedberg <johan.hedberg@intel.com>2014-01-11 18:56:03 +0200
commita3299e5b1e61155fd97114ca6df61ed35957e7a1 (patch)
treecf6430d23f746d5c56fb2aaaccdc5c5da9d811f1 /attrib
parentcceb59d76b24c477c2ab120cd8e9803b6e352c57 (diff)
downloadbluez-a3299e5b1e61155fd97114ca6df61ed35957e7a1.tar.gz
attrib: Add extra PDU checks when decoding Read by Type Response
These checks are needed to avoid invalid memory access on bogus PDUs.
Diffstat (limited to 'attrib')
-rw-r--r--attrib/att.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/attrib/att.c b/attrib/att.c
index 183390b5b..e28be25fc 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -454,7 +454,24 @@ struct att_data_list *dec_read_by_type_resp(const uint8_t *pdu, size_t len)
if (pdu[0] != ATT_OP_READ_BY_TYPE_RESP)
return NULL;
+ /* PDU must contain at least:
+ * - Attribute Opcode (1 octet)
+ * - Length (1 octet)
+ * - Attribute Data List (at least one entry):
+ * - Attribute Handle (2 octets)
+ * - Attribute Value (at least 1 octet) */
+ if (len < 5)
+ return NULL;
+
elen = pdu[1];
+ /* Minimum Attribute Data List size */
+ if (elen < 3)
+ return NULL;
+
+ /* Reject incomplete Attribute Data List */
+ if ((len - 2) % elen)
+ return NULL;
+
num = (len - 2) / elen;
list = att_data_list_alloc(num, elen);
if (list == NULL)