public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Witowski <jakub.witowski@silvair.com>
To: linux-bluetooth@vger.kernel.org
Cc: Inga Stotland <inga.stotland@intel.com>
Subject: [RFC BlueZ 1/1] mesh: Validate element indexation
Date: Mon,  8 Jul 2019 16:13:14 +0200	[thread overview]
Message-ID: <20190708141314.13950-2-jakub.witowski@silvair.com> (raw)
In-Reply-To: <20190708141314.13950-1-jakub.witowski@silvair.com>

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


  reply	other threads:[~2019-07-08 14:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-08 14:13 [RFC BlueZ 0/1] Validate element indexation Jakub Witowski
2019-07-08 14:13 ` Jakub Witowski [this message]
2019-07-08 16:53 ` Stotland, Inga
2019-07-08 18:22   ` Michał Lowas-Rzechonek
2019-07-09  6:36     ` Stotland, Inga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190708141314.13950-2-jakub.witowski@silvair.com \
    --to=jakub.witowski@silvair.com \
    --cc=inga.stotland@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox