From ba6cbdfbecc9cb9bc5f4078b63e6889538e6ed93 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 4 Sep 2024 20:47:31 +0200 Subject: esp32 wifi driver fix --- fw/esp32/components/eos/wifi.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/fw/esp32/components/eos/wifi.c b/fw/esp32/components/eos/wifi.c index 537aeba..2be169f 100755 --- a/fw/esp32/components/eos/wifi.c +++ b/fw/esp32/components/eos/wifi.c @@ -154,35 +154,33 @@ static void wifi_handler(unsigned char _mtype, unsigned char *buffer, uint16_t b case EOS_WIFI_MTYPE_CONNECT: { wifi_config_t wifi_sta_config; size_t ssid_size = sizeof(wifi_sta_config.sta.ssid); - size_t pwd_size = sizeof(wifi_sta_config.sta.password) - 1; - size_t ssid_len, pwd_len; + size_t pwd_size = sizeof(wifi_sta_config.sta.password); + unsigned char ssid_len, pwd_len; char *ssid, *pwd; buffer++; - buf_len--; + + ssid_len = *buffer; + buffer++; ssid = (char *)buffer; - ssid_len = strnlen(ssid, buf_len); - if (ssid_len == buf_len) break; if (ssid_len > ssid_size) break; - buffer += ssid_len + 1; - buf_len -= ssid_len + 1; + buffer += ssid_len; + + pwd_len = *buffer; + buffer++; pwd = (char *)buffer; - pwd_len = strnlen(pwd, buf_len); - if (pwd_len == buf_len) break; - if (pwd_len >= pwd_size) break; - buffer += pwd_len + 1; - buf_len -= pwd_len + 1; + if (pwd_len > pwd_size - 1) break; + buffer += pwd_len; memset(&wifi_sta_config, 0, sizeof(wifi_sta_config)); + memcpy(wifi_sta_config.sta.ssid, ssid, ssid_len); if (ssid_len < ssid_size) { - strcpy((char *)wifi_sta_config.sta.ssid, ssid); - } else { - memcpy(wifi_sta_config.sta.ssid, ssid, ssid_size); + wifi_sta_config.sta.ssid[ssid_len] = '\0'; } - strcpy((char *)wifi_sta_config.sta.password, pwd); - wifi_sta_config.sta.password[pwd_size] = '\0'; + memcpy((char *)wifi_sta_config.sta.password, pwd, pwd_len); + wifi_sta_config.sta.password[pwd_len] = '\0'; ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_sta_config); if (ret) break; @@ -265,8 +263,8 @@ ssize_t eos_wifi_get_status(unsigned char *buffer) { p++; } - strcpy((char *)p, (char *)ap_info.ssid); - p += len + 1; + memcpy((char *)p, (char *)ap_info.ssid, len); + p += len; break; } @@ -333,7 +331,7 @@ void eos_wifi_send_scan(void) { for (i=0; i EOS_NET_MTU) break; + if (p - rbuf + len + 1 > EOS_NET_SIZE_BUF) break; strcpy((char *)p, (char *)scan_r[i].ssid); p += len + 1; -- cgit v1.2.3