From: Luiz Augusto von Dentz Date: Wed, 3 Jun 2020 17:31:59 +0000 (-0700) Subject: gatt: Fix possible crash when unable to generate hash X-Git-Tag: accepted/tizen/unified/20210607.124421~110 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b48d863f9a7518704cca90b03d6f8a27c25157c;p=platform%2Fupstream%2Fbluez.git gatt: Fix possible crash when unable to generate hash 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 Signed-off-by: Ayush Garg --- diff --git a/src/gatt-database.c b/src/gatt-database.c index d298d29..d4873eb 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -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) { diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 412fae1..bc917ee 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -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) diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h index 2403bfb..55d6608 100644 --- a/src/shared/gatt-db.h +++ b/src/shared/gatt-db.h @@ -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,