mesh: Fix reading device UUID from Join() call
PATCH 1/2 mesh: Fix reading device UUID from Join() call
Supply correct parameters to l_dbus_message_iter_get_fixed_array to get the location from where to read UUID value.
--- mesh/mesh.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mesh/mesh.c +4 -1
@@ -564,6 +564,7 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, {const char *app_path, *sender;struct l_dbus_message_iter iter_uuid; +uint8_t *uuid;uint32_t n;l_debug ("Join network request" );
@@ -578,7 +579,7 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, join_pending = l_new(struct join_data, 1); -l_dbus_message_iter_get_fixed_array (&iter_uuid, join_pending->uuid, &n); +l_dbus_message_iter_get_fixed_array (&iter_uuid, &uuid, &n);if (n !=16 ) {l_free (join_pending);
@@ -587,6 +588,8 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, "Bad device UUID"); } +memcpy (join_pending->uuid, uuid,16 ); + sender =l_dbus_message_get_sender (msg); join_pending->sender =l_strdup (sender);
Signature · 1 line
2.17.2
PATCH 2/2 mesh: Clean up when finishing the Join call
Consolidate multiple instances where the pending Join data is freed into calling one function free_pending_join_call().
Also, add checks for NULL data in cleanup functions for storage, agent and provisioning acceptor.
--- mesh/agent.c | 2 +- mesh/mesh.c | 59 +++++++++++++++++++------------------------- mesh/prov-acceptor.c | 5 ++-- mesh/storage.c | 3 +++ 4 files changed, 32 insertions(+), 37 deletions(-)
mesh/agent.c +1 -1
@@ -210,7 +210,7 @@ static void agent_free(void *agent_data)void mesh_agent_remove (struct mesh_agent *agent) { -if (!l_queue_find (agents, simple_match, agent)) +if (!agent || !l_queue_find (agents, simple_match, agent))return ;agent_free (agent);
mesh/mesh.c +25 -34
93 lines not on this page · raw message
mesh/prov-acceptor.c +3 -2
@@ -118,9 +118,10 @@ static struct mesh_prov_acceptor *prov = NULL;static void acceptor_free (void ) { +if (!prov) +return ; -if (prov) -l_timeout_remove (prov->timeout); +l_timeout_remove (prov->timeout);mesh_send_cancel (bec_filter,sizeof (bec_filter));mesh_send_cancel (&pkt_filter,sizeof (pkt_filter));
mesh/storage.c +3 -0
@@ -573,6 +573,9 @@ void storage_remove_node_config(struct mesh_node *node)struct json_object *jnode;const char *dir_name; +if (!node) +return ; + jnode =node_jconfig_get (node);if (jnode)json_object_put (jnode);
Signature · 1 line
2.17.2
Re: [PATCH BlueZ 2/2] mesh: Clean up when finishing the Join call
Patch Applied
Quoted 158 lines · Inga Stotland
Consolidate multiple instances where the pending Join data is freed into calling one function
free_pending_join_call().Also, add checks for NULL data in cleanup functions for storage, agent and provisioning acceptor.
--- mesh/agent.c | 2 +- mesh/mesh.c | 59 +++++++++++++++++++------------------------- mesh/prov-acceptor.c | 5 ++-- mesh/storage.c | 3 +++ 4 files changed, 32 insertions(+), 37 deletions(-)mesh/agent.c +1
-1@@ -210,7 +210,7 @@ static void agent_free(void *agent_data)void mesh_agent_remove (struct mesh_agent *agent) { -if (!l_queue_find (agents, simple_match, agent)) +if (!agent || !l_queue_find (agents, simple_match, agent))return ;agent_free (agent);mesh/mesh.c +25
-34@@ -345,6 +345,28 @@ static void attach_exit(void *data)l_free (pending); } +static void free_pending_join_call (bool failed) +{ +if (!join_pending) +return ; + +if (join_pending->disc_watch) +l_dbus_remove_watch (dbus_get_bus (), + join_pending->disc_watch); + +acceptor_cancel (&mesh); + +mesh_agent_remove (join_pending->agent); + +if (failed) { +storage_remove_node_config (join_pending->node); +node_free (join_pending->node); + } + +l_free (join_pending); + join_pending =NULL ; +} +void mesh_cleanup (void ) {struct l_dbus_message *reply;@@ -353,19 +375,12 @@ void mesh_cleanup(void)mgmt_unref (mgmt_mesh);if (join_pending) { +/* The Join() call failed since it has not been completed */ reply =dbus_error (join_pending->msg,MESH_ERROR_FAILED ,"Failed. Exiting" );l_dbus_send (dbus_get_bus (), reply); -if (join_pending->disc_watch) -l_dbus_remove_watch (dbus_get_bus (), - join_pending->disc_watch); - -if (join_pending->node) -node_free (join_pending->node); - -l_free (join_pending); - join_pending =NULL ; +free_pending_join_call (true); }l_queue_destroy (attach_queue, attach_exit);@@ -404,26 +419,6 @@ const char *mesh_status_str(uint8_t err) } } -static void free_pending_join_call (bool failed) -{ -if (!join_pending) -return ; - -if (join_pending->disc_watch) -l_dbus_remove_watch (dbus_get_bus (), - join_pending->disc_watch); - -mesh_agent_remove (join_pending->agent); - -if (failed) { -storage_remove_node_config (join_pending->node); -mesh_agent_remove (join_pending->agent); - } - -l_free (join_pending); - join_pending =NULL ; -} -/* This is being called if the app exits unexpectedly */ static void prov_disc_cb (struct l_dbus *bus,void *user_data) {@@ -433,8 +428,6 @@ static void prov_disc_cb(struct l_dbus *bus, void *user_data)if (join_pending->msg)l_dbus_message_unref (join_pending->msg); -acceptor_cancel (&mesh); - join_pending->disc_watch =0 ;free_pending_join_call (true);@@ -553,9 +546,7 @@ static void node_init_cb(struct mesh_node *node, struct mesh_agent *agent) fail:l_dbus_send (dbus_get_bus (), reply); -mesh_agent_remove (join_pending->agent); -l_free (join_pending); - join_pending =NULL ; +free_pending_join_call (true); } static struct l_dbus_message *join_network_call(struct l_dbus *dbus,mesh/prov-acceptor.c +3
-2@@ -118,9 +118,10 @@ static struct mesh_prov_acceptor *prov = NULL;static void acceptor_free (void ) { +if (!prov) +return ; -if (prov) -l_timeout_remove (prov->timeout); +l_timeout_remove (prov->timeout);mesh_send_cancel (bec_filter,sizeof (bec_filter));mesh_send_cancel (&pkt_filter,sizeof (pkt_filter));mesh/storage.c +3
-0@@ -573,6 +573,9 @@ void storage_remove_node_config(struct mesh_node *node)struct json_object *jnode;const char *dir_name; +if (!node) +return ; + jnode =node_jconfig_get (node);if (jnode)json_object_put (jnode);
Patch Applied
Quoted 36 lines · Inga Stotland
Supply correct parameters to
l_dbus_message_iter_get_fixed_arrayto get the location from where to read UUID value.--- mesh/mesh.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)mesh/mesh.c +4
-1@@ -564,6 +564,7 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, {const char *app_path, *sender;struct l_dbus_message_iter iter_uuid; +uint8_t *uuid;uint32_t n;l_debug ("Join network request" );@@ -578,7 +579,7 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, join_pending = l_new(struct join_data, 1); -l_dbus_message_iter_get_fixed_array (&iter_uuid, join_pending->uuid, &n); +l_dbus_message_iter_get_fixed_array (&iter_uuid, &uuid, &n);if (n !=16 ) {l_free (join_pending);@@ -587,6 +588,8 @@ static struct l_dbus_message *join_network_call(struct l_dbus *dbus, "Bad device UUID"); } +memcpy (join_pending->uuid, uuid,16 ); + sender =l_dbus_message_get_sender (msg); join_pending->sender =l_strdup (sender);