summaryrefslogtreecommitdiff
path: root/attrib
diff options
context:
space:
mode:
authorLukasz Rymanowski <lukasz.rymanowski@tieto.com>2015-02-26 10:39:29 +0100
committerSzymon Janc <szymon.janc@tieto.com>2015-02-27 16:33:56 +0100
commit746663a2c13b3de345eec51bd68bce61140520b2 (patch)
tree9116c58ac78cc7037adf4e4cc9c705622a5e10ab /attrib
parent6590e993628f95a08061e240ca6fe6463066d178 (diff)
downloadbluez-746663a2c13b3de345eec51bd68bce61140520b2.tar.gz
attrib/gatt: Improve robustness on search primary services
Without this it is possible to put BlueZ into infinite loop when doing primary service search on remote device. Issue happens when remote device replies with ending handle which is lower than start handle we use for search. This patch fixes that Found on robustness session on UPF50
Diffstat (limited to 'attrib')
-rw-r--r--attrib/gatt.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/attrib/gatt.c b/attrib/gatt.c
index aafd3f77d..b8d766cd2 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -43,6 +43,7 @@ struct discover_primary {
GAttrib *attrib;
unsigned int id;
bt_uuid_t uuid;
+ uint16_t start;
GSList *primaries;
gatt_cb_t cb;
void *user_data;
@@ -255,8 +256,19 @@ static void primary_by_uuid_cb(guint8 status, const guint8 *ipdu,
if (range->end == 0xffff)
goto done;
+ /*
+ * 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 (range->end < dp->start) {
+ err = ATT_ECODE_UNLIKELY;
+ goto done;
+ }
+
+ dp->start = range->end + 1;
+
buf = g_attrib_get_buffer(dp->attrib, &buflen);
- oplen = encode_discover_primary(range->end + 1, 0xffff, &dp->uuid,
+ oplen = encode_discover_primary(dp->start, 0xffff, &dp->uuid,
buf, buflen);
if (oplen == 0)
@@ -325,12 +337,24 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
att_data_list_free(list);
err = 0;
+ /*
+ * 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 (end < dp->start) {
+ err = ATT_ECODE_UNLIKELY;
+ goto done;
+ }
+
+ dp->start = end + 1;
+
if (end != 0xffff) {
size_t buflen;
uint8_t *buf = g_attrib_get_buffer(dp->attrib, &buflen);
- guint16 oplen = encode_discover_primary(end + 1, 0xffff, NULL,
+ guint16 oplen = encode_discover_primary(dp->start, 0xffff, NULL,
buf, buflen);
+
g_attrib_send(dp->attrib, dp->id, buf, oplen, primary_all_cb,
discover_primary_ref(dp),
discover_primary_unref);
@@ -362,6 +386,7 @@ guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
dp->attrib = g_attrib_ref(attrib);
dp->cb = func;
dp->user_data = user_data;
+ dp->start = 0x0001;
if (uuid) {
dp->uuid = *uuid;