Diff between 9800e88493004bd5406f166205ded8784a635b47 and d5af19f22cb525b4b2a00cb149064270e2943a35

Changed Files

File Additions Deletions Status
src/shared/gatt-helpers.c +14 -1 modified

Full Patch

diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index a11f4c1..744211f 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -1336,10 +1336,22 @@ static void read_by_type_cb(uint8_t opcode, const void *pdu,
 	}
 
 	last_handle = get_le16(pdu + length - data_length);
+
+	/*
+	 * If last handle is lower from previous start handle then it is smth
+	 * wrong. Let's stop search, otherwise we might enter infinite loop.
+	 */
+	if (last_handle < op->start_handle) {
+		success = false;
+		goto done;
+	}
+
+	op->start_handle = last_handle + 1;
+
 	if (last_handle != op->end_handle) {
 		uint8_t pdu[4 + get_uuid_len(&op->uuid)];
 
-		put_le16(last_handle + 1, pdu);
+		put_le16(op->start_handle, pdu);
 		put_le16(op->end_handle, pdu + 2);
 		bt_uuid_to_le(&op->uuid, pdu + 4);
 
@@ -1381,6 +1393,7 @@ bool bt_gatt_read_by_type(struct bt_att *att, uint16_t start, uint16_t end,
 	op->callback = callback;
 	op->user_data = user_data;
 	op->destroy = destroy;
+	op->start_handle = start;
 	op->end_handle = end;
 	op->uuid = *uuid;