[RFC BlueZ 1/1] mesh: Validate element indexation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This implementation checks if there is no gap between given element_indexes
---
 mesh/node.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/mesh/node.c b/mesh/node.c
index 1f781cfe9..35f85b0f2 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -1439,6 +1439,14 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 	return true;
 }
 
+static void collect_ele_idxs(void *a, void *b)
+{
+	const struct node_element *element = a;
+	uint64_t *ele_idx_list = (uint64_t *)b;
+
+	*ele_idx_list |= (1 << element->idx);
+}
+
 static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 {
 	struct l_dbus_message_iter objects, interfaces;
@@ -1449,6 +1457,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 	bool have_app = false;
 	bool is_new;
 	uint8_t num_ele;
+	uint64_t ele_idx_list = 0;
 
 	is_new = (req->type != REQUEST_TYPE_ATTACH);
 
@@ -1533,6 +1542,12 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 		goto fail;
 	}
 
+	/* Check for proper element indexation */
+	l_queue_foreach(node->elements, collect_ele_idxs, &ele_idx_list);
+
+	if (((ele_idx_list + 1) & ele_idx_list) != 0)
+		goto fail;
+
 	if (req->type == REQUEST_TYPE_ATTACH) {
 		node_ready_func_t cb = req->cb;
 
-- 
2.20.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux