diff mbox series

[BlueZ] mesh: Use valid net key index when handling Send call

Message ID 20200821054856.41857-1-inga.stotland@intel.com (mailing list archive)
State Accepted
Headers show
Series [BlueZ] mesh: Use valid net key index when handling Send call | expand

Commit Message

Stotland, Inga Aug. 21, 2020, 5:48 a.m. UTC
Retrieve value of bound Net Key index based on the value of
passed AppKey index. Check if the key is present and fail early
in case of error. Also, pass the correct NetKey index to model
layer in mesh_model_send(), instead of hard coded 0.
---
 mesh/model.c |  2 --
 mesh/node.c  | 13 +++++++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

Comments

Brian Gix Aug. 22, 2020, 2:21 p.m. UTC | #1
Applied
On Thu, 2020-08-20 at 22:48 -0700, Inga Stotland wrote:
> Retrieve value of bound Net Key index based on the value of
> passed AppKey index. Check if the key is present and fail early
> in case of error. Also, pass the correct NetKey index to model
> layer in mesh_model_send(), instead of hard coded 0.
> ---
>  mesh/model.c |  2 --
>  mesh/node.c  | 13 +++++++++----
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/mesh/model.c b/mesh/model.c
> index eb5142503..7e1c4ab92 100644
> --- a/mesh/model.c
> +++ b/mesh/model.c
> @@ -547,8 +547,6 @@ static bool msg_send(struct mesh_node *node, bool cred, uint16_t src,
>  			l_debug("no app key for (%x)", app_idx);
>  			return false;
>  		}
> -
> -		net_idx = appkey_net_idx(node_get_net(node), app_idx);
>  	}
>  
>  	out = l_malloc(out_len);
> diff --git a/mesh/node.c b/mesh/node.c
> index 1eeffeb8b..ed3d959c5 100644
> --- a/mesh/node.c
> +++ b/mesh/node.c
> @@ -1761,7 +1761,7 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus,
>  	const char *sender, *ele_path;
>  	struct l_dbus_message_iter iter_data;
>  	struct node_element *ele;
> -	uint16_t dst, app_idx, src;
> +	uint16_t dst, app_idx, net_idx, src;
>  	uint8_t *data;
>  	uint32_t len;
>  
> @@ -1790,10 +1790,15 @@ static struct l_dbus_message *send_call(struct l_dbus *dbus,
>  
>  	if (app_idx & ~APP_IDX_MASK)
>  		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
> -						"Invalid key_index");
> +						"Invalid key index");
> +
> +	net_idx = appkey_net_idx(node_get_net(node), app_idx);
> +	if (net_idx == NET_IDX_INVALID)
> +		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
> +							"Key not found");
>  
> -	if (!mesh_model_send(node, src, dst, app_idx, 0, DEFAULT_TTL, false,
> -								data, len))
> +	if (!mesh_model_send(node, src, dst, app_idx, net_idx, DEFAULT_TTL,
> +							false, data, len))
>  		return dbus_error(msg, MESH_ERROR_FAILED, NULL);
>  
>  	return l_dbus_message_new_method_return(msg);
diff mbox series

Patch

diff --git a/mesh/model.c b/mesh/model.c
index eb5142503..7e1c4ab92 100644
--- a/mesh/model.c
+++ b/mesh/model.c
@@ -547,8 +547,6 @@  static bool msg_send(struct mesh_node *node, bool cred, uint16_t src,
 			l_debug("no app key for (%x)", app_idx);
 			return false;
 		}
-
-		net_idx = appkey_net_idx(node_get_net(node), app_idx);
 	}
 
 	out = l_malloc(out_len);
diff --git a/mesh/node.c b/mesh/node.c
index 1eeffeb8b..ed3d959c5 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -1761,7 +1761,7 @@  static struct l_dbus_message *send_call(struct l_dbus *dbus,
 	const char *sender, *ele_path;
 	struct l_dbus_message_iter iter_data;
 	struct node_element *ele;
-	uint16_t dst, app_idx, src;
+	uint16_t dst, app_idx, net_idx, src;
 	uint8_t *data;
 	uint32_t len;
 
@@ -1790,10 +1790,15 @@  static struct l_dbus_message *send_call(struct l_dbus *dbus,
 
 	if (app_idx & ~APP_IDX_MASK)
 		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
-						"Invalid key_index");
+						"Invalid key index");
+
+	net_idx = appkey_net_idx(node_get_net(node), app_idx);
+	if (net_idx == NET_IDX_INVALID)
+		return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
+							"Key not found");
 
-	if (!mesh_model_send(node, src, dst, app_idx, 0, DEFAULT_TTL, false,
-								data, len))
+	if (!mesh_model_send(node, src, dst, app_idx, net_idx, DEFAULT_TTL,
+							false, data, len))
 		return dbus_error(msg, MESH_ERROR_FAILED, NULL);
 
 	return l_dbus_message_new_method_return(msg);