gatt: Fix possible crash when unable to generate hash
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 3 Jun 2020 17:31:59 +0000 (10:31 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:49 +0000 (14:30 +0530)
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.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/gatt-database.c
src/shared/gatt-db.c
src/shared/gatt-db.h

index d298d29..d4873eb 100644 (file)
@@ -1430,10 +1430,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_hash_support(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) {
index 412fae1..bc917ee 100644 (file)
@@ -601,6 +601,14 @@ uint8_t *gatt_db_get_hash(struct gatt_db *db)
        return db->hash;
 }
 
+bool gatt_db_hash_support(struct gatt_db *db)
+{
+       if (!db || !db->crypto)
+               return false;
+
+       return true;
+}
+
 static struct gatt_db_service *find_insert_loc(struct gatt_db *db,
                                                uint16_t start, uint16_t end,
                                                struct gatt_db_service **after)
index 2403bfb..55d6608 100644 (file)
@@ -41,6 +41,7 @@ bool gatt_db_remove_service(struct gatt_db *db,
 bool gatt_db_clear(struct gatt_db *db);
 bool gatt_db_clear_range(struct gatt_db *db, uint16_t start_handle,
                                                        uint16_t end_handle);
+bool gatt_db_hash_support(struct gatt_db *db);
 uint8_t *gatt_db_get_hash(struct gatt_db *db);
 
 struct gatt_db_attribute *gatt_db_insert_service(struct gatt_db *db,