From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 2/8] unit/test-gatt: Add malformed Read By Type response tests
Date: Fri, 6 Nov 2026 13:33:44 -0500 [thread overview]
Message-ID: <20261106183350.3155282-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261106183350.3155282-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Add tests for Read By Type responses with invalid Attribute Data Length,
truncated data, empty values and an empty Server Features value.
Assisted-by: OpenCode:claude-opus-5.5
---
unit/test-gatt.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 6d6d0c73ed40..26768e1aca82 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -2064,6 +2064,18 @@ static const struct test_step test_read_by_type_6 = {
.expected_att_ecode = 0x0c,
};
+static const struct test_step test_read_by_type_malformed = {
+ .handle = 0x0001,
+ .end_handle = 0xffff,
+};
+
+static const struct test_step test_read_by_type_empty = {
+ .handle = 0x0001,
+ .end_handle = 0xffff,
+ .expected_att_ecode = 0x0a,
+ .value = read_data_1,
+};
+
static void multiple_read_cb(bool success, uint8_t att_ecode,
const uint8_t *value, uint16_t length,
void *user_data)
@@ -2146,6 +2158,7 @@ static void read_by_type_cb(bool success, uint8_t att_ecode,
struct bt_gatt_iter iter;
g_assert(att_ecode == step->expected_att_ecode);
+ g_assert(success == !!step->value);
if (success) {
uint16_t length, handle;
@@ -2957,6 +2970,81 @@ int main(int argc, char *argv[])
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x0c));
+ define_test_att("/read-by-type/zero-data-length", test_read_by_type,
+ &uuid_char_16, &test_read_by_type_malformed,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x00, 0x0a, 0x00));
+
+ define_test_att("/read-by-type/short-data-length", test_read_by_type,
+ &uuid_char_16, &test_read_by_type_malformed,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x01, 0x0a, 0x00));
+
+ define_test_att("/read-by-type/missing-data", test_read_by_type,
+ &uuid_char_16, &test_read_by_type_malformed,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x12));
+
+ define_test_att("/read-by-type/short-handle", test_read_by_type,
+ &uuid_char_16, &test_read_by_type_malformed,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x02, 0x0a));
+
+ define_test_att("/read-by-type/oversized-data-length",
+ test_read_by_type,
+ &uuid_char_16, &test_read_by_type_malformed,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x04, 0x0a, 0x00));
+
+ define_test_att("/read-by-type/truncated-data", test_read_by_type,
+ &uuid_char_16, &test_read_by_type_malformed,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x03, 0x0a, 0x00, 0x01, 0x0b));
+
+ define_test_att("/read-by-type/empty-value", test_read_by_type,
+ &uuid_char_16, &test_read_by_type_empty,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x09, 0x02, 0x0a, 0x00),
+ raw_pdu(0x08, 0x0b, 0x00, 0xff, 0xff, 0x0d, 0x2a),
+ raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x0a));
+
+ define_test_client("/read-by-type/empty-server-features", test_client,
+ service_db_1, NULL,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x3a, 0x2b),
+ raw_pdu(0x09, 0x02, 0xff, 0xff),
+ raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
+ raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01,
+ 0x18),
+ raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
+ raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d,
+ 0x18),
+ raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
+ raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
+ raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
+ raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
+ raw_pdu(0x08, 0x01, 0x00, 0x08, 0x00, 0x02, 0x28),
+ raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
+ raw_pdu(0x08, 0x01, 0x00, 0x08, 0x00, 0x03, 0x28),
+ raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00,
+ 0x00, 0x2a),
+ raw_pdu(0x08, 0x03, 0x00, 0x08, 0x00, 0x03, 0x28),
+ raw_pdu(0x09, 0x07, 0x06, 0x00, 0x0a, 0x07, 0x00,
+ 0x29, 0x2a),
+ raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
+ raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
+ raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
+ raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
+ raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
+ raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29));
+
define_test_server("/TP/GAR/SR/BV-03-C/small", test_server, ts_small_db,
NULL,
raw_pdu(0x03, 0x00, 0x02),
--
2.56.0
next prev parent reply other threads:[~2026-11-06 18:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 18:33 [PATCH BlueZ v2 0/8] Fix handling of malformed GATT PDUs Luiz Augusto von Dentz
2026-11-06 18:33 ` [PATCH BlueZ v2 1/8] shared/gatt: Validate Read By Type responses Luiz Augusto von Dentz
2026-11-06 23:18 ` Fix handling of malformed GATT PDUs bluez.test.bot
2026-11-06 18:33 ` Luiz Augusto von Dentz [this message]
2026-11-06 18:33 ` [PATCH BlueZ v2 3/8] shared/gatt-client: Fix handling of short notifications Luiz Augusto von Dentz
2026-11-06 18:33 ` [PATCH BlueZ v2 4/8] unit/test-gatt: Add short notification test Luiz Augusto von Dentz
2026-11-06 18:33 ` [PATCH BlueZ v2 5/8] shared/att: Add Read Multiple Variable Length opcodes Luiz Augusto von Dentz
2026-11-06 18:33 ` [PATCH BlueZ v2 6/8] shared/gatt-client: Fix parsing Read Multiple Variable Length response Luiz Augusto von Dentz
2026-11-06 18:33 ` [PATCH BlueZ v2 7/8] shared/gatt-client: Check value lengths before reading them Luiz Augusto von Dentz
2026-11-06 18:33 ` [PATCH BlueZ v2 8/8] unit/test-gatt: Add Read Multiple Variable Length tests Luiz Augusto von Dentz
2026-11-07 21:00 ` [PATCH BlueZ v2 0/8] Fix handling of malformed GATT PDUs patchwork-bot+bluetooth
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=20261106183350.3155282-3-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.