From 15c75974de75135c7d9c5be983043fff4db3652e Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Fri, 27 Oct 2017 14:07:47 +0800 Subject: [PATCH] component/bt: fix crash when set device name NULL --- components/bt/bluedroid/api/esp_bt_device.c | 4 +++- examples/bluetooth/gatt_server/main/gatts_demo.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/api/esp_bt_device.c b/components/bt/bluedroid/api/esp_bt_device.c index b4885cc0e..c50ada980 100644 --- a/components/bt/bluedroid/api/esp_bt_device.c +++ b/components/bt/bluedroid/api/esp_bt_device.c @@ -36,7 +36,9 @@ esp_err_t esp_bt_dev_set_device_name(const char *name) if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { return ESP_ERR_INVALID_STATE; } - + if (!name){ + return ESP_ERR_INVALID_ARG; + } if (strlen(name) > ESP_DEV_DEVICE_NAME_MAX) { return ESP_ERR_INVALID_ARG; } diff --git a/examples/bluetooth/gatt_server/main/gatts_demo.c b/examples/bluetooth/gatt_server/main/gatts_demo.c index 8c30fd326..a60d567c8 100644 --- a/examples/bluetooth/gatt_server/main/gatts_demo.c +++ b/examples/bluetooth/gatt_server/main/gatts_demo.c @@ -313,7 +313,10 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.len = ESP_UUID_LEN_16; gl_profile_tab[PROFILE_A_APP_ID].service_id.id.uuid.uuid.uuid16 = GATTS_SERVICE_UUID_TEST_A; - esp_ble_gap_set_device_name(TEST_DEVICE_NAME); + esp_err_t set_dev_name_ret = esp_ble_gap_set_device_name(TEST_DEVICE_NAME); + if (set_dev_name_ret){ + ESP_LOGE(GATTS_TAG, "set device name failed, error code = %x", set_dev_name_ret); + } #ifdef CONFIG_SET_RAW_ADV_DATA esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data)); if (raw_adv_ret){