From a92470e6626af03f6fd0fad0eb9bb94105604262 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 11 Jun 2015 16:01:58 +0300 Subject: [PATCH] shared/gatt-db: Fix allocating characteristic at 0xffff All caracteristics shall contain a value in the next handle so having a declaration on 0xffff is invalid since there won't be any space for the value descriptor. --- src/shared/gatt-db.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 5e1537e64..7f863ef02 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -706,6 +706,18 @@ service_insert_characteristic(struct gatt_db_service *service, if (handle && handle <= service->attributes[0]->handle) return NULL; + /* + * It is not possible to allocate last handle for a Characteristic + * since it would not have space for its value: + * 3.3.2 Characteristic Value Declaration + * The Characteristic Value declaration contains the value of the + * characteristic. It is the first Attribute after the characteristic + * declaration. All characteristic definitions shall have a + * Characteristic Value declaration. + */ + if (handle == UINT16_MAX) + return NULL; + i = get_attribute_index(service, 1); if (!i) return NULL; -- 2.47.3