From 6dfe404d327f401b184fc2954a818739b3f0da54 Mon Sep 17 00:00:00 2001 From: "anuj.bhumiya" Date: Tue, 21 Jul 2020 16:15:05 +0530 Subject: [PATCH] Mesh: SVACE defect fixes Change-Id: I1afb0f6433dd5d976e5e859d2235e63c0346344d Signed-off-by: anuj.bhumiya --- bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c | 21 ++++++++++++++++++--- bt-oal/hardware/bt_mesh.h | 3 ++- bt-service/services/mesh/bt-service-mesh-cdb.c | 7 ++++++- .../services/mesh/bt-service-mesh-config-client.c | 7 ++++--- bt-service/services/mesh/bt-service-mesh-util.c | 4 ++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c index 671c6bc..99163ad 100644 --- a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c @@ -107,6 +107,7 @@ static struct mesh_provision_auth_action auth_table[] = { { "out-numeric", BT_HAL_MESH_AUTH_NUMERIC_DISPLAY}, { "out-alpha", BT_HAL_MESH_AUTH_ALPHANUMERIC_DISPLAY}, { "static-oob", BT_HAL_MESH_AUTH_REQ_OOB_STATIC_KEY_INPUT}, + { "unknown", BT_HAL_MESH_UNKNOWN_AUTH_METHOD}, }; @@ -144,8 +145,12 @@ static bt_hal_mesh_auth_variant_e __mesh_get_authentication_type(char *str) if (len == strlen(auth_table[i].action) && !strcmp(str, auth_table[i].action)) break; - - return auth_table[i].auth_type; + if (i < sz) { + return auth_table[i].auth_type; + } else { + ERR("Mesh : Not A Proper Authentication Type!"); + return BT_HAL_MESH_UNKNOWN_AUTH_METHOD; + } } enum mesh_dbus_interface_e { @@ -1222,7 +1227,9 @@ static struct l_dbus_message *__mesh_agent_display_string_request( } INFO("Mesh:[OUT] AlphaNumeric Authentication: Value [%s]", str); - ev.auth_type = BT_HAL_MESH_AUTH_ALPHANUMERIC_DISPLAY; + ev.auth_type = __mesh_get_authentication_type(str); + if (ev.auth_type == BT_HAL_MESH_UNKNOWN_AUTH_METHOD) + return l_dbus_message_new_error(msg, dbus_err_fail, NULL); g_strlcpy(ev.auth_value, str, sizeof(ev.auth_value)); if (mesh_event_cb) @@ -1277,6 +1284,8 @@ static struct l_dbus_message *__mesh_agent_display_numeric_request( INFO("Mesh:[OUT] Numeric Authentication type [%s] value [%u]", str, n); auth_value = l_strdup_printf("%u",n); ev.auth_type = __mesh_get_authentication_type(str); + if (ev.auth_type == BT_HAL_MESH_UNKNOWN_AUTH_METHOD) + return l_dbus_message_new_error(msg, dbus_err_fail, NULL); g_strlcpy(ev.auth_value, auth_value, sizeof(ev.auth_value)); if (mesh_event_cb) @@ -1332,6 +1341,8 @@ static struct l_dbus_message *__mesh_agent_prompt_numeric_request( INFO("Mesh:[IN] Numeric Authentication type [%s]", str); ev.auth_type = __mesh_get_authentication_type(str); + if (ev.auth_type == BT_HAL_MESH_UNKNOWN_AUTH_METHOD) + return l_dbus_message_new_error(msg, dbus_err_fail, NULL); agent_msg = msg; l_dbus_message_ref(msg); if (mesh_event_cb) @@ -1384,6 +1395,8 @@ static struct l_dbus_message *__mesh_agent_prompt_static_request( INFO("Mesh: [IN] AlphaNumeric Authentication type [%s]", str); ev.auth_type = __mesh_get_authentication_type(str); + if (ev.auth_type == BT_HAL_MESH_UNKNOWN_AUTH_METHOD) + return l_dbus_message_new_error(msg, dbus_err_fail, NULL); agent_msg = msg; l_dbus_message_ref(msg); if (mesh_event_cb) @@ -2319,6 +2332,8 @@ bt_status_t _bt_hal_mesh_send_configuration_message( l1 = g_slist_find_custom(app->elements, GUINT_TO_POINTER(src_elem_idx), __compare_element_index); + if (!l1) + return BT_STATUS_FAIL; elem = l1->data; req = l_new(struct configuration_request, 1); diff --git a/bt-oal/hardware/bt_mesh.h b/bt-oal/hardware/bt_mesh.h index bad0439..d9e77bc 100644 --- a/bt-oal/hardware/bt_mesh.h +++ b/bt-oal/hardware/bt_mesh.h @@ -41,7 +41,8 @@ typedef enum { /**< OOB Key Inputs */ BT_HAL_MESH_AUTH_REQ_OOB_PUBLIC_KEY_INPUT, - BT_HAL_MESH_AUTH_REQ_OOB_STATIC_KEY_INPUT + BT_HAL_MESH_AUTH_REQ_OOB_STATIC_KEY_INPUT, + BT_HAL_MESH_UNKNOWN_AUTH_METHOD } bt_hal_mesh_auth_variant_e; /* Spec defined Error Codes */ diff --git a/bt-service/services/mesh/bt-service-mesh-cdb.c b/bt-service/services/mesh/bt-service-mesh-cdb.c index 00418a9..75cb15e 100644 --- a/bt-service/services/mesh/bt-service-mesh-cdb.c +++ b/bt-service/services/mesh/bt-service-mesh-cdb.c @@ -917,8 +917,12 @@ uint16_t** _bt_mesh_conf_get_all_model_info(_bt_mesh_cdb_t *cfg, jentry = json_object_array_get_idx(jmodelarray, i); str = json_object_get_string(jentry); /* Only standard models are handled now */ - if (sscanf(str, "%04hx", models[i]) != 1) + if (sscanf(str, "%04hx", models[i]) != 1) { + for (int j =0 ; j < sz; j++) + g_free(models[j]); + g_free(models); return NULL; + } } /* TODO: Need to handle vendor models */ *num_models = sz; @@ -1435,6 +1439,7 @@ _bt_mesh_cdb_t* _bt_mesh_conf_load(const char *file_name, sz = read(fd, str, st.st_size); if (sz != st.st_size) { BT_ERR("Mesh: Failed to read configuration file [%s]", file_name); + g_free(str); return NULL; } diff --git a/bt-service/services/mesh/bt-service-mesh-config-client.c b/bt-service/services/mesh/bt-service-mesh-config-client.c index e8c552a..a9bfac4 100644 --- a/bt-service/services/mesh/bt-service-mesh-config-client.c +++ b/bt-service/services/mesh/bt-service-mesh-config-client.c @@ -1104,6 +1104,8 @@ void _bt_mesh_config_client_devkey_msg_handler( /* Extract Period */ param.period = data[7]; + if (!cmd) + break; if (cmd->opcode == MESH_OPCODE_CONFIG_MODEL_PUB_GET) __bt_mesh_handle_pending_dev_config_request_info(result, @@ -1925,9 +1927,8 @@ int _bt_mesh_model_set_publication(const char *app_cred, const char *sender, _bt_mesh_util_convert_string_to_hex(req->net_uuid, strlen(req->net_uuid), net_uuid.uuid, 16); - if (req->pub_addr > MESH_ALL_NODES_ADDRESS) - return BLUETOOTH_ERROR_INVALID_PARAM; - + if (req->pub_addr == MESH_ALL_NODES_ADDRESS) + BT_INFO("Mesh: Setting Publication to ALL Node Address"); if (!MESH_IS_GROUP(req->pub_addr) && !MESH_IS_VIRTUAL(req->pub_addr) && req->pub_addr != MESH_UNASSIGNED_ADDRESS) { diff --git a/bt-service/services/mesh/bt-service-mesh-util.c b/bt-service/services/mesh/bt-service-mesh-util.c index 08fe99a..12629e2 100644 --- a/bt-service/services/mesh/bt-service-mesh-util.c +++ b/bt-service/services/mesh/bt-service-mesh-util.c @@ -92,11 +92,11 @@ void _bt_mesh_util_print_byte_array(const char *prefix, int i; line = g_malloc(strlen(prefix) + (16 * 3) + 2); - sprintf(line, "%s ", prefix); + snprintf(line, strlen(prefix), "%s ", prefix); bytes = line + strlen(prefix) + 1; for (i = 0; i < len; ++i) { - sprintf(bytes, "%2.2x ", data[i]); + snprintf(bytes, 4, "%2.2x ", data[i]); if ((i + 1) % 16) { bytes += 3; } else { -- 2.7.4