diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 401f551..6016b06 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
{
struct bt_gatt_client *client = op->client;
struct service_changed_op *next_sc_op;
- uint16_t start_handle = 0, end_handle = 0;
+ uint16_t start_handle = op->start;
+ uint16_t end_handle = op->end;
+ bool services_found = false;
client->in_svc_chngd = false;
if (!op->result_head || !op->result_tail)
goto next;
- start_handle = op->result_head->service.start_handle;
- end_handle = op->result_tail->service.end_handle;
+ services_found = true;
/* Insert all newly discovered services in their correct place as a
* contiguous chunk */
}
/* Check if the GATT service is not present or has remained unchanged */
- if (!start_handle || !client->svc_chngd_val_handle ||
+ if (!services_found || !client->svc_chngd_val_handle ||
client->svc_chngd_val_handle < start_handle ||
client->svc_chngd_val_handle > end_handle)
return;
start = get_le16(value);
end = get_le16(value + 2);
+ if (start > end) {
+ util_debug(client->debug_callback, client->debug_data,
+ "Service Changed received with invalid handles");
+ return;
+ }
+
util_debug(client->debug_callback, client->debug_data,
"Service Changed received - start: 0x%04x end: 0x%04x",
start, end);