Skip to contentSkip to conversation

gatt: Fix possible crash when unable to generate hash

PATCH In review Luiz Augusto von Dentz 1 participant 2 messages Jun 3, 2020 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 gatt: Fix possible crash when unable to generate hash

From: Luiz Augusto von Dentz <[email protected]>

gatt_db_get_hash actually depends on crypto so platforms that don't have it enabled shall not register GATT_CHARAC_DB_HASH as otherwise it would cause a crash due to hash being NULL.

---
 src/gatt-database.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
src/gatt-database.c +6 -2
index 8cbe09bae..d717bbcde 100644
@@ -1211,10 +1211,14 @@ static void populate_gatt_service(struct btd_gatt_database *database)
 				cli_feat_read_cb, cli_feat_write_cb,
 				database);
 
-	bt_uuid16_create(&uuid, GATT_CHARAC_DB_HASH);
-	database->db_hash = gatt_db_service_add_characteristic(service,
+
+	/* Only expose database hash chrc if supported */
+	if (gatt_db_get_hash(database->db)) {
+		bt_uuid16_create(&uuid, GATT_CHARAC_DB_HASH);
+		database->db_hash = gatt_db_service_add_characteristic(service,
 				&uuid, BT_ATT_PERM_READ, BT_GATT_CHRC_PROP_READ,
 				db_hash_read_cb, NULL, database);
+	}
 
 	/* Only enable EATT if there is a socket listening */
 	if (database->eatt_io) {
Signature · 1 line
2.25.3
author maintainer
#1 lore raw

Hi,

Quoted 32 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

gatt_db_get_hash actually depends on crypto so platforms that don't have it enabled shall not register GATT_CHARAC_DB_HASH as otherwise it would cause a crash due to hash being NULL.

---
 src/gatt-database.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
src/gatt-database.c +6 -3
index 8cbe09bae..d717bbcde 100644
@@ -1211,10 +1211,14 @@ static void populate_gatt_service(struct btd_gatt_database *database)
                                cli_feat_read_cb, cli_feat_write_cb,
                                database);
 
-       bt_uuid16_create(&uuid, GATT_CHARAC_DB_HASH);
-       database->db_hash = gatt_db_service_add_characteristic(service,
+
+       /* Only expose database hash chrc if supported */
+       if (gatt_db_get_hash(database->db)) {
+               bt_uuid16_create(&uuid, GATT_CHARAC_DB_HASH);
+               database->db_hash = gatt_db_service_add_characteristic(service,
                                &uuid, BT_ATT_PERM_READ, BT_GATT_CHRC_PROP_READ,
                                db_hash_read_cb, NULL, database);
+       }
 
        /* Only enable EATT if there is a socket listening */
        if (database->eatt_io) {
--
Quoted 1 line

2.25.3

Push.

Signature · 1 line
Luiz Augusto von Dentz