public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Alicia Boya Garcia <ntrrgc@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Alicia Boya Garcia <ntrrgc@gmail.com>
Subject: [PATCH BlueZ] client: Fix uninitialized read in attribute handle
Date: Mon,  8 Aug 2022 11:22:07 +0200	[thread overview]
Message-ID: <20220808092206.153221-1-ntrrgc@gmail.com> (raw)

When services, characteristics and descriptors were parsed from DBus
proxies the client code was calling the print code without initializing
the `handle` field, which the print functions use.

This resulted in semi-random or zero handles in all attributes when
using gatt.list-attributes in bluetoothctl, depending on compilation
flags.

This patch fixes the problem by parsing the handle from the DBus proxy
path.
---
 client/gatt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/client/gatt.c b/client/gatt.c
index 4c1efaf75..aaad786b2 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -158,6 +158,16 @@ static void print_inc_service(struct service *service, const char *description)
 					service->uuid, text);
 }
 
+static uint16_t handle_from_path(const char *path)
+{
+	const char *number = path + strlen(path) - 4;
+
+	if (number < path)
+		return 0;
+
+	return (uint16_t) strtol(number, NULL, 16);
+}
+
 static void print_service_proxy(GDBusProxy *proxy, const char *description)
 {
 	struct service service;
@@ -179,6 +189,7 @@ static void print_service_proxy(GDBusProxy *proxy, const char *description)
 	service.path = (char *) g_dbus_proxy_get_path(proxy);
 	service.uuid = (char *) uuid;
 	service.primary = primary;
+	service.handle = handle_from_path(service.path);
 
 	print_service(&service, description);
 }
@@ -261,6 +272,7 @@ static void print_characteristic(GDBusProxy *proxy, const char *description)
 	memset(&chrc, 0, sizeof(chrc));
 	chrc.path = (char *) g_dbus_proxy_get_path(proxy);
 	chrc.uuid = (char *) uuid;
+	chrc.handle = handle_from_path(chrc.path);
 
 	print_chrc(&chrc, description);
 }
@@ -355,6 +367,7 @@ static void print_descriptor(GDBusProxy *proxy, const char *description)
 	memset(&desc, 0, sizeof(desc));
 	desc.path = (char *) g_dbus_proxy_get_path(proxy);
 	desc.uuid = (char *) uuid;
+	desc.handle = handle_from_path(desc.path);
 
 	print_desc(&desc, description);
 }
-- 
2.37.1


             reply	other threads:[~2022-08-08  9:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  9:22 Alicia Boya Garcia [this message]
2022-08-08 10:21 ` [BlueZ] client: Fix uninitialized read in attribute handle bluez.test.bot
2022-08-08 20:08 ` [PATCH BlueZ] " Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2022-08-07 19:20 Alicia Boya Garcia

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=20220808092206.153221-1-ntrrgc@gmail.com \
    --to=ntrrgc@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