From 6b4beef4aace6e05fa3786fc4d9b96a002cefd5e Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov Date: Fri, 8 Jun 2018 13:48:15 +0100 Subject: [PATCH] wifi: Fix crash in ent auth when user is not set https://github.com/mongoose-os-libs/wifi/issues/8 CL: wifi: Fix crash in ent auth when user is not set PUBLISHED_FROM=a30aa6696c7041c288a9ae4d3d7f64b2f71615df --- esp32/src/esp32_wifi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/esp32/src/esp32_wifi.c b/esp32/src/esp32_wifi.c index a5e14e3..19c171e 100644 --- a/esp32/src/esp32_wifi.c +++ b/esp32/src/esp32_wifi.c @@ -293,17 +293,18 @@ bool mgos_wifi_dev_sta_setup(const struct mgos_config_wifi_sta *cfg) { if (!mgos_conf_str_empty(cfg->cert) || !mgos_conf_str_empty(cfg->user)) { /* WPA-enterprise mode */ static char *s_ca_cert_pem = NULL, *s_cert_pem = NULL, *s_key_pem = NULL; + const char *user = cfg->user; - esp_wifi_sta_wpa2_ent_set_username((unsigned char *) cfg->user, - strlen(cfg->user)); + if (user == NULL) user = ""; + + esp_wifi_sta_wpa2_ent_set_username((unsigned char *) user, strlen(user)); if (!mgos_conf_str_empty(cfg->anon_identity)) { esp_wifi_sta_wpa2_ent_set_identity((unsigned char *) cfg->anon_identity, strlen(cfg->anon_identity)); } else { /* By default, username is used. */ - esp_wifi_sta_wpa2_ent_set_identity((unsigned char *) cfg->user, - strlen(cfg->user)); + esp_wifi_sta_wpa2_ent_set_identity((unsigned char *) user, strlen(user)); } if (!mgos_conf_str_empty(cfg->pass)) { esp_wifi_sta_wpa2_ent_set_password((unsigned char *) cfg->pass,