public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] input/device: Fix off by one report descriptor size error
@ 2025-12-06  1:52 Andrey Smirnov
  2025-12-06  3:39 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Andrey Smirnov @ 2025-12-06  1:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrey Smirnov, Luiz Augusto von Dentz

Due to the way we handle SDP strings internally BlueZ ends up
including and artifically added 0x00 into the report descriptor it
passes on to UHID. This results in kernel error messages like

[371225.240843] microsoft 0005:045E:02FD.0019: unknown main item tag 0x0

or

[367200.458679] playstation 0005:054C:0CE6.0014: unknown main item tag 0x0

The error is ignored by the kernel's report parser, so this is benign,
but for the sake of correctness, let's not supply bogus data in the
first place.
---
 profiles/input/device.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 02a9ad43d..6bdc5ee3a 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -863,10 +863,17 @@ static int extract_hid_desc_data(const sdp_record_t *rec,
 	if (!d || !SDP_IS_TEXT_STR(d->dtd))
 		goto invalid_desc;

-	req->rd_data = g_try_malloc0(d->unitSize);
+	/*
+	 * Report descriptor data is parsed by extract_str() which
+	 * will allocate N + 1 bytes for the incoming string to
+	 * include a zero delimiter. Since that zero delimiter isn't a
+	 * part of a report descriptor we adjust the size here to
+	 * account for that.
+	 */
+	req->rd_size = d->unitSize - 1;
+	req->rd_data = g_try_malloc0(req->rd_size);
 	if (req->rd_data) {
-		memcpy(req->rd_data, d->val.str, d->unitSize);
-		req->rd_size = d->unitSize;
+		memcpy(req->rd_data, d->val.str, req->rd_size);
 		epox_endian_quirk(req->rd_data, req->rd_size);
 	}

--
2.43.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-06  3:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-06  1:52 [PATCH BlueZ] input/device: Fix off by one report descriptor size error Andrey Smirnov
2025-12-06  3:39 ` [BlueZ] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox