shared/gatt-client: fix overflow bug in find_service_for_handle
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.
Signed-off-by Jakub Pawlowski <[email protected]>
--- src/shared/gatt-db.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
src/shared/gatt-db.c +2 -3
@@ -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
Hi Jakub,
Quoted 27 lines · Jakub Pawlowski
find_service_for_handlewas manually computing end handle. It was causing overflow for last service in range, that always ends at0xFFFF. That caused service for handle not being found.Signed-off-by Jakub Pawlowski <[email protected]>--- src/shared/gatt-db.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)src/shared/gatt-db.c +2
-4@@ -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