Skip to contentSkip to conversation

shared/gatt-client: fix overflow bug in find_service_for_handle

PATCH Applied Jakub Pawlowski 2 participants 2 messages Feb 4, 2015 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shared/gatt-client: fix overflow bug in find_service_for_handle

find_service_for_handle was manually computing end handle. It was causing overflow for last service in range, that always ends at 0xFFFF. That caused service for handle not being found.

---
 src/shared/gatt-db.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/shared/gatt-db.c +2 -3
index 780d640..f72d58e 100644
@@ -1170,10 +1170,9 @@ static bool find_service_for_handle(const void *data, const void *user_data)
 	uint16_t handle = PTR_TO_UINT(user_data);
 	uint16_t start, end;
 
-	start = service->attributes[0]->handle;
-	end = start + service->num_handles;
+	gatt_db_service_get_handles(service, &start, &end);
 
-	return (start <= handle) && (handle < end);
+	return (start <= handle) && (handle <= end);
 }
 
 struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
Signature · 1 line
2.2.0.rc0.207.ga3a616c
maintainer Applied
#1 lore raw

Hi Jakub,

Quoted 27 lines · Jakub Pawlowski

find_service_for_handle was manually computing end handle. It was causing overflow for last service in range, that always ends at 0xFFFF. That caused service for handle not being found.

---
 src/shared/gatt-db.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/shared/gatt-db.c +2 -4
index 780d640..f72d58e 100644
@@ -1170,10 +1170,9 @@ static bool find_service_for_handle(const void *data, const void *user_data)
        uint16_t handle = PTR_TO_UINT(user_data);
        uint16_t start, end;
 
-       start = service->attributes[0]->handle;
-       end = start + service->num_handles;
+       gatt_db_service_get_handles(service, &start, &end);
 
-       return (start <= handle) && (handle < end);
+       return (start <= handle) && (handle <= end);
 }
 
 struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
--
Quoted 1 line

2.2.0.rc0.207.ga3a616c

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz