mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/strncpy_issue_in_wifi_example' into 'master'
replace strncpy with strlcpy in wifi examples for safety's sake Closes IDF-695 See merge request idf/esp-idf!5192
This commit is contained in:
commit
7ec9f9ee74
@ -302,8 +302,7 @@ static esp_err_t start_wifi_ap(const char *ssid, const char *pass)
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
strlcpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
||||||
wifi_config.ap.ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid));
|
|
||||||
|
|
||||||
if (strlen(pass) == 0) {
|
if (strlen(pass) == 0) {
|
||||||
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
||||||
|
@ -288,8 +288,7 @@ static esp_err_t start_wifi_ap(const char *ssid, const char *pass)
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
strncpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
strlcpy((char *) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
||||||
wifi_config.ap.ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid));
|
|
||||||
|
|
||||||
if (strlen(pass) == 0) {
|
if (strlen(pass) == 0) {
|
||||||
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
memset(wifi_config.ap.password, 0, sizeof(wifi_config.ap.password));
|
||||||
|
@ -26,7 +26,7 @@ static EventGroupHandle_t wifi_event_group;
|
|||||||
const int CONNECTED_BIT = BIT0;
|
const int CONNECTED_BIT = BIT0;
|
||||||
|
|
||||||
|
|
||||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
{
|
{
|
||||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||||
@ -61,9 +61,9 @@ static bool wifi_join(const char *ssid, const char *pass, int timeout_ms)
|
|||||||
{
|
{
|
||||||
initialise_wifi();
|
initialise_wifi();
|
||||||
wifi_config_t wifi_config = { 0 };
|
wifi_config_t wifi_config = { 0 };
|
||||||
strncpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
strlcpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
||||||
if (pass) {
|
if (pass) {
|
||||||
strncpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
strlcpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||||
|
@ -53,7 +53,7 @@ static EventGroupHandle_t wifi_event_group;
|
|||||||
const int CONNECTED_BIT = BIT0;
|
const int CONNECTED_BIT = BIT0;
|
||||||
const int DISCONNECTED_BIT = BIT1;
|
const int DISCONNECTED_BIT = BIT1;
|
||||||
|
|
||||||
static void scan_done_handler(void* arg, esp_event_base_t event_base,
|
static void scan_done_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
{
|
{
|
||||||
uint16_t sta_number = 0;
|
uint16_t sta_number = 0;
|
||||||
@ -76,14 +76,14 @@ static void scan_done_handler(void* arg, esp_event_base_t event_base,
|
|||||||
ESP_LOGI(TAG, "sta scan done");
|
ESP_LOGI(TAG, "sta scan done");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void got_ip_handler(void* arg, esp_event_base_t event_base,
|
static void got_ip_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
{
|
{
|
||||||
xEventGroupClearBits(wifi_event_group, DISCONNECTED_BIT);
|
xEventGroupClearBits(wifi_event_group, DISCONNECTED_BIT);
|
||||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void disconnect_handler(void* arg, esp_event_base_t event_base,
|
static void disconnect_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
{
|
{
|
||||||
if (reconnect) {
|
if (reconnect) {
|
||||||
@ -128,7 +128,7 @@ static bool wifi_cmd_sta_join(const char* ssid, const char* pass)
|
|||||||
|
|
||||||
strlcpy((char*) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
strlcpy((char*) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
||||||
if (pass) {
|
if (pass) {
|
||||||
strncpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
strlcpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bits & CONNECTED_BIT) {
|
if (bits & CONNECTED_BIT) {
|
||||||
@ -205,14 +205,14 @@ static bool wifi_cmd_ap_set(const char* ssid, const char* pass)
|
|||||||
};
|
};
|
||||||
|
|
||||||
reconnect = false;
|
reconnect = false;
|
||||||
strncpy((char*) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
strlcpy((char*) wifi_config.ap.ssid, ssid, sizeof(wifi_config.ap.ssid));
|
||||||
if (pass) {
|
if (pass) {
|
||||||
if (strlen(pass) != 0 && strlen(pass) < 8) {
|
if (strlen(pass) != 0 && strlen(pass) < 8) {
|
||||||
reconnect = true;
|
reconnect = true;
|
||||||
ESP_LOGE(TAG, "password less than 8");
|
ESP_LOGE(TAG, "password less than 8");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
strncpy((char*) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
|
strlcpy((char*) wifi_config.ap.password, pass, sizeof(wifi_config.ap.password));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(pass) == 0) {
|
if (strlen(pass) == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user