From: Sebastian <seb.witt@googlemail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Sebastian <seb.witt@googlemail.com>
Subject: [PATCH v3 5/6] unit/test-gatt: Add tests for long reads beyond 512 octets
Date: Thu, 3 Dec 2026 16:34:07 +0100 [thread overview]
Message-ID: <20261203153408.31769-6-seb.witt@googlemail.com> (raw)
In-Reply-To: <20261203153408.31769-1-seb.witt@googlemail.com>
Check that a value longer than BT_ATT_MAX_VALUE_LEN is truncated by
bt_gatt_client_read_long_value, read in full by
bt_gatt_client_read_long_value_max_len and truncated to the maximum
length given, and that reads starting beyond the maximum length are
refused.
---
unit/test-gatt.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 3a35ccbc1..70edf6c14 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -71,6 +71,13 @@ struct context {
#define data(args...) ((const unsigned char[]) { args })
+#define array_pdu(array) \
+ { \
+ .valid = true, \
+ .data = util_memdup(array, sizeof(array)), \
+ .size = sizeof(array), \
+ }
+
#define raw_pdu(args...) \
{ \
.valid = true, \
@@ -373,6 +380,7 @@ struct test_step {
uint16_t length;
uint8_t features;
bool init_fail;
+ uint16_t max_len;
};
static void destroy_context(struct context *context)
@@ -2496,6 +2504,66 @@ static const struct test_step test_long_read_8 = {
.expected_att_ecode = 0x0c
};
+/* A value longer than BT_ATT_MAX_VALUE_LEN, as exposed by some
+ * non-compliant devices, read with a Read Response and a Read Blob
+ * Response.
+ */
+static const uint8_t long_data_600[600] = { [0 ... 599] = 0xff };
+static const uint8_t long_read_rsp_600[512] = {
+ BT_ATT_OP_READ_RSP, [1 ... 511] = 0xff
+};
+static const uint8_t long_read_blob_rsp_600[90] = {
+ BT_ATT_OP_READ_BLOB_RSP, [1 ... 89] = 0xff
+};
+
+static void test_long_read_max_len(struct context *context)
+{
+ const struct test_step *step = context->data->step;
+
+ g_assert(bt_gatt_client_read_long_value_max_len(context->client,
+ step->handle, 0, step->max_len,
+ multiple_read_cb, context,
+ NULL));
+}
+
+static const struct test_step test_long_read_max_len_1 = {
+ .handle = 0x0003,
+ .func = test_long_read_max_len,
+ .max_len = 4096,
+ .value = long_data_600,
+ .length = sizeof(long_data_600)
+};
+
+static const struct test_step test_long_read_max_len_2 = {
+ .handle = 0x0003,
+ .func = test_long_read_max_len,
+ .max_len = 550,
+ .value = long_data_600,
+ .length = 550
+};
+
+static void test_long_read_offset(struct context *context)
+{
+ const struct test_step *step = context->data->step;
+
+ /* A read starting beyond the maximum length is refused without
+ * sending any request.
+ */
+ g_assert(!bt_gatt_client_read_long_value(context->client,
+ step->handle, BT_ATT_MAX_VALUE_LEN + 1,
+ multiple_read_cb, context, NULL));
+ g_assert(!bt_gatt_client_read_long_value_max_len(context->client,
+ step->handle, 101, 100,
+ multiple_read_cb, context, NULL));
+
+ context_quit(context);
+}
+
+static const struct test_step test_long_read_offset_1 = {
+ .handle = 0x0003,
+ .func = test_long_read_offset,
+};
+
/* Descriptor test data's */
static const struct test_step test_long_read_9 = {
@@ -3703,6 +3771,34 @@ int main(int argc, char *argv[])
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x0b, 0x01, 0x02, 0x03));
+ define_test_client("/robustness/read-long-512", test_client,
+ service_db_1, &test_long_read_2,
+ SERVICE_DATA_1_PDUS,
+ raw_pdu(0x0a, 0x03, 0x00),
+ array_pdu(long_read_rsp_600),
+ raw_pdu(0x0c, 0x03, 0x00, 0xff, 0x01),
+ array_pdu(long_read_blob_rsp_600));
+
+ define_test_client("/robustness/read-long-max-len", test_client,
+ service_db_1, &test_long_read_max_len_1,
+ SERVICE_DATA_1_PDUS,
+ raw_pdu(0x0a, 0x03, 0x00),
+ array_pdu(long_read_rsp_600),
+ raw_pdu(0x0c, 0x03, 0x00, 0xff, 0x01),
+ array_pdu(long_read_blob_rsp_600));
+
+ define_test_client("/robustness/read-long-max-len/truncated",
+ test_client, service_db_1, &test_long_read_max_len_2,
+ SERVICE_DATA_1_PDUS,
+ raw_pdu(0x0a, 0x03, 0x00),
+ array_pdu(long_read_rsp_600),
+ raw_pdu(0x0c, 0x03, 0x00, 0xff, 0x01),
+ array_pdu(long_read_blob_rsp_600));
+
+ define_test_client("/robustness/read-long-offset", test_client,
+ service_db_1, &test_long_read_offset_1,
+ SERVICE_DATA_1_PDUS);
+
define_test_client("/TP/GAR/CL/BI-17-C", test_client, service_db_1,
&test_long_read_8,
SERVICE_DATA_1_PDUS,
--
2.56.1
next prev parent reply other threads:[~2026-12-03 15:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CABBYNZ+GNO-eVNC5B_4SqCdHOE+OHmXUaW0NwStd_BsbUzx35A@mail.gmail.com>
2026-11-30 20:45 ` [PATCH v2 0/4] Accept HoG Report Map longer than 512 octets Sebastian
2026-11-30 20:45 ` [PATCH v2 1/4] shared/gatt-client: Add bt_gatt_client_read_long_value_max_len Sebastian
2026-12-01 0:02 ` Accept HoG Report Map longer than 512 octets bluez.test.bot
2026-12-02 16:13 ` Luiz Augusto von Dentz
2026-11-30 20:45 ` [PATCH v2 2/4] main.conf: Add LongReportMap option to [Input] Sebastian
2026-11-30 20:45 ` [PATCH v2 3/4] shared/hog: Add bt_hog_set_long_report_map Sebastian
2026-11-30 20:45 ` [PATCH v2 4/4] input/hog: Accept Report Map longer than 512 octets Sebastian
2026-12-03 15:34 ` [PATCH v3 0/6] Accept HoG " Sebastian
2026-12-03 15:34 ` [PATCH v3 1/6] shared/gatt-client: Add bt_gatt_client_read_long_value_max_len Sebastian
2026-12-03 15:34 ` [PATCH v3 2/6] main.conf: Add LongReportMap option to [Input] Sebastian
2026-12-03 15:34 ` [PATCH v3 3/6] shared/hog: Add bt_hog_set_long_report_map Sebastian
2026-12-03 15:34 ` [PATCH v3 4/6] input/hog: Accept Report Map longer than 512 octets Sebastian
2026-12-03 15:34 ` Sebastian [this message]
2026-12-03 15:34 ` [PATCH v3 6/6] unit/test-hog: Add tests for long Report Map Sebastian
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=20261203153408.31769-6-seb.witt@googlemail.com \
--to=seb.witt@googlemail.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