From: Isak Westin Date: Fri, 23 Sep 2022 11:31:49 +0000 (+0200) Subject: mesh: Reply error if appkey added for wrong netkey X-Git-Tag: accepted/tizen/unified/20230608.164325~67 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63fc73f88141ff93e5e562caae2bbfc06216884c;p=platform%2Fupstream%2Fbluez.git mesh: Reply error if appkey added for wrong netkey If a known appkey is added for a different netkey, the status reply should be Invalid NetKey. Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- diff --git a/mesh/appkey.c b/mesh/appkey.c index c9450da0..a4bf49be 100644 --- a/mesh/appkey.c +++ b/mesh/appkey.c @@ -295,7 +295,9 @@ int appkey_key_add(struct mesh_net *net, uint16_t net_idx, uint16_t app_idx, key = l_queue_find(app_keys, match_key_index, L_UINT_TO_PTR(app_idx)); if (key) { - if (memcmp(new_key, key->key, 16) == 0) + if (key->net_idx != net_idx) + return MESH_STATUS_INVALID_NETKEY; + else if (memcmp(new_key, key->key, 16) == 0) return MESH_STATUS_SUCCESS; else return MESH_STATUS_IDX_ALREADY_STORED;