OSDN Git Service

attrib: Fix condition check for attr delete
authorBharat Panda <bharat.panda@samsung.com>
Tue, 23 Sep 2014 12:19:17 +0000 (17:49 +0530)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 13 Feb 2015 13:02:14 +0000 (15:02 +0200)
Checks handle value for non-zero as well as >= 0xffff, to avoid
infinite loop and deletion of unspecified attrib handles.

attrib/gatt-service.c

index f592a70..4e1a654 100644 (file)
@@ -299,9 +299,15 @@ static void service_attr_del(struct btd_adapter *adapter, uint16_t start_handle,
 {
        uint16_t handle;
 
-       for (handle = start_handle; handle <= end_handle; handle++)
+       /* For a 128-bit category primary service below handle should be checked
+        * for both non-zero as well as >= 0xffff. As on last iteration the
+        * handle will turn to 0 from 0xffff and loop will be infinite.
+        */
+       for (handle = start_handle; (handle != 0 && handle <= end_handle);
+                                                               handle++) {
                if (attrib_db_del(adapter, handle) < 0)
                        error("Can't delete handle 0x%04x", handle);
+       }
 }
 
 gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,