From b25cffd4d5b2c07b4697b453b0fe9f8b09c2092f Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 29 May 2020 16:43:35 +0800 Subject: [PATCH] ble_mesh: Add more checks of net_idx & app_idx --- .../api/core/esp_ble_mesh_networking_api.c | 14 +++++++++++--- .../api/models/esp_ble_mesh_config_model_api.c | 12 ++++++++---- .../api/models/esp_ble_mesh_generic_model_api.c | 12 +++++++++--- .../api/models/esp_ble_mesh_health_model_api.c | 12 +++++++++--- .../api/models/esp_ble_mesh_lighting_model_api.c | 12 +++++++++--- .../api/models/esp_ble_mesh_sensor_model_api.c | 10 ++++++++-- .../api/models/esp_ble_mesh_time_scene_model_api.c | 12 +++++++++--- 7 files changed, 63 insertions(+), 21 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c index 080cf190dd..db6b6a144b 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c @@ -179,9 +179,12 @@ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model, esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode, uint16_t length, uint8_t *data) { - if (!model || !ctx) { + if (model == NULL || ctx == NULL || + ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED || + ctx->app_idx == ESP_BLE_MESH_KEY_UNUSED) { return ESP_ERR_INVALID_ARG; } + return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_SERVER_MODEL_SEND, length, data, 0, false, ROLE_NODE); } @@ -191,9 +194,12 @@ esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model, uint16_t length, uint8_t *data, int32_t msg_timeout, bool need_rsp, esp_ble_mesh_dev_role_t device_role) { - if (!model || !ctx) { + if (model == NULL || ctx == NULL || + ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED || + ctx->app_idx == ESP_BLE_MESH_KEY_UNUSED) { return ESP_ERR_INVALID_ARG; } + return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND, length, data, msg_timeout, need_rsp, device_role); } @@ -202,9 +208,11 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod uint16_t length, uint8_t *data, esp_ble_mesh_dev_role_t device_role) { - if (!model || !model->pub || !model->pub->msg) { + if (model == NULL || model->pub == NULL || model->pub->msg == NULL || + model->pub->publish_addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; } + return ble_mesh_model_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH, length, data, 0, false, device_role); } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c index e6870d0864..c419339840 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c @@ -58,8 +58,10 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_ btc_ble_mesh_config_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) || - (config_client_get_need_param(params->opcode) && !get_state)) { + if (params == NULL || params->model == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + !ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) || + (config_client_get_need_param(params->opcode) && get_state == NULL)) { return ESP_ERR_INVALID_ARG; } @@ -81,8 +83,10 @@ esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_ btc_ble_mesh_config_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) || - (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && !set_state)) { + if (params == NULL || params->model == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + !ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) || + (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set_state == NULL)) { return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c index cb2b22a95d..b93a1f97f3 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c @@ -45,8 +45,11 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param btc_ble_mesh_generic_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || - (generic_client_get_need_param(params->opcode) && !get_state)) { + if (params == NULL || params->model == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED || + (generic_client_get_need_param(params->opcode) && get_state == NULL)) { return ESP_ERR_INVALID_ARG; } @@ -68,7 +71,10 @@ esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param btc_ble_mesh_generic_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || !set_state) { + if (params == NULL || params->model == NULL || set_state == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c index 506e906c17..7c3b666f6f 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c @@ -39,8 +39,11 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_ btc_ble_mesh_health_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || (!get_state && - params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET)) { + if (params == NULL || params->model == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED || + (params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET && get_state == NULL)) { return ESP_ERR_INVALID_ARG; } @@ -62,7 +65,10 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_ btc_ble_mesh_health_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || !set_state) { + if (params == NULL || params->model == NULL || set_state == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c index c7847cc266..127941b41c 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c @@ -32,8 +32,11 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t btc_ble_mesh_lighting_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || (!get_state && - params->opcode == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET)) { + if (params == NULL || params->model == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED || + (params->opcode == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET && get_state == NULL)) { return ESP_ERR_INVALID_ARG; } @@ -55,7 +58,10 @@ esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t btc_ble_mesh_lighting_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || !set_state) { + if (params == NULL || params->model == NULL || set_state == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c index 2d23d37db4..8bf77b3858 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c @@ -32,7 +32,10 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_ btc_ble_mesh_sensor_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || !get_state) { + if (params == NULL || params->model == NULL || get_state == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; } @@ -54,7 +57,10 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_ btc_ble_mesh_sensor_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || !set_state) { + if (params == NULL || params->model == NULL || set_state == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c index 80347934d6..bd71ea7cd5 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c @@ -32,8 +32,11 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa btc_ble_mesh_time_scene_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || (!get_state && - params->opcode == ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET)) { + if (params == NULL || params->model == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED || + (params->opcode == ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET && get_state == NULL)) { return ESP_ERR_INVALID_ARG; } @@ -55,7 +58,10 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa btc_ble_mesh_time_scene_client_args_t arg = {0}; btc_msg_t msg = {0}; - if (!params || !params->model || !params->ctx.addr || !set_state) { + if (params == NULL || params->model == NULL || set_state == NULL || + params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED || + params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { return ESP_ERR_INVALID_ARG; }