From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 1/4] gatt-server: Check prepare write length before reallocating
Date: Thu, 10 Sep 2026 14:42:13 -0400 [thread overview]
Message-ID: <20260910184216.1601639-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
append_prep_data() grew the buffer and copied the new fragment into it
before rejecting a total length above UINT16_MAX. On overflow the
allocation had already been enlarged and written while prep_data->length
was left at its previous value, desynchronising the buffer from its
tracked size.
Move the bound check ahead of the realloc() so an oversized prepare
write queue is rejected without touching the buffer.
Assisted-by: opencode:claude-opus-5
---
src/shared/gatt-server.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c
index 516fceb8ed00..fde791aae867 100644
--- a/src/shared/gatt-server.c
+++ b/src/shared/gatt-server.c
@@ -1207,6 +1207,8 @@ static bool append_prep_data(struct prep_write_data *prep_data, uint16_t handle,
return true;
len = (size_t)prep_data->length + (size_t)length;
+ if (len > UINT16_MAX)
+ return false;
val = realloc(prep_data->value, len);
if (!val)
@@ -1215,9 +1217,6 @@ static bool append_prep_data(struct prep_write_data *prep_data, uint16_t handle,
memcpy(val + prep_data->length, value, length);
prep_data->value = val;
-
- if (len > UINT16_MAX)
- return false;
prep_data->length = (uint16_t)len;
return true;
--
2.55.0
next reply other threads:[~2026-09-10 18:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 18:42 Luiz Augusto von Dentz [this message]
2026-09-10 18:42 ` [PATCH BlueZ v1 2/4] adapter: Unify the A2DP admin allowlist UUID mapping Luiz Augusto von Dentz
2026-09-10 18:42 ` [PATCH BlueZ v1 3/4] battery: Document the unknown sentinels and fix a stale name Luiz Augusto von Dentz
2026-09-10 18:42 ` [PATCH BlueZ v1 4/4] client/bluetoothctl: Declare the controller helper in its own header Luiz Augusto von Dentz
2026-09-10 20:06 ` [BlueZ,v1,1/4] gatt-server: Check prepare write length before reallocating bluez.test.bot
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=20260910184216.1601639-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox