Better length checks
This commit is contained in:
parent
6446010753
commit
b191075ab8
@ -249,7 +249,9 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
|
|||||||
bool connected = ((bits & WIFI_CONNECTED_BIT) != 0) &&
|
bool connected = ((bits & WIFI_CONNECTED_BIT) != 0) &&
|
||||||
!((bits & WIFI_DISCONNECTED_BIT) != 0);
|
!((bits & WIFI_DISCONNECTED_BIT) != 0);
|
||||||
if (connected) {
|
if (connected) {
|
||||||
if (memcmp(ssid, config->sta.ssid, ssid_len) == 0) {
|
// SSIDs are up to 32 bytes. Assume it is null terminated if it is less.
|
||||||
|
if (memcmp(ssid, config->sta.ssid, ssid_len) == 0 &&
|
||||||
|
(ssid_len == 32 || strlen((const char *)config->sta.ssid) == ssid_len)) {
|
||||||
// Already connected to the desired network.
|
// Already connected to the desired network.
|
||||||
return WIFI_RADIO_ERROR_NONE;
|
return WIFI_RADIO_ERROR_NONE;
|
||||||
} else {
|
} else {
|
||||||
@ -272,7 +274,9 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t
|
|||||||
set_mode_station(self, true);
|
set_mode_station(self, true);
|
||||||
|
|
||||||
memcpy(&config->sta.ssid, ssid, ssid_len);
|
memcpy(&config->sta.ssid, ssid, ssid_len);
|
||||||
|
if (ssid_len < 32) {
|
||||||
config->sta.ssid[ssid_len] = 0;
|
config->sta.ssid[ssid_len] = 0;
|
||||||
|
}
|
||||||
memcpy(&config->sta.password, password, password_len);
|
memcpy(&config->sta.password, password, password_len);
|
||||||
config->sta.password[password_len] = 0;
|
config->sta.password[password_len] = 0;
|
||||||
config->sta.channel = channel;
|
config->sta.channel = channel;
|
||||||
|
@ -257,6 +257,7 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
|
|
||||||
mp_buffer_info_t ssid;
|
mp_buffer_info_t ssid;
|
||||||
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
||||||
|
mp_arg_validate_length_range(ssid.len, 1, 32, MP_QSTR_ssid);
|
||||||
|
|
||||||
mp_buffer_info_t password;
|
mp_buffer_info_t password;
|
||||||
password.len = 0;
|
password.len = 0;
|
||||||
@ -330,9 +331,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||||||
mp_buffer_info_t ssid;
|
mp_buffer_info_t ssid;
|
||||||
ssid.len = 0;
|
ssid.len = 0;
|
||||||
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ);
|
||||||
if (ssid.len > 32) {
|
mp_arg_validate_length_range(ssid.len, 1, 32, MP_QSTR_ssid);
|
||||||
mp_raise_ValueError(translate("ssid can't be more than 32 bytes"));
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_buffer_info_t password;
|
mp_buffer_info_t password;
|
||||||
password.len = 0;
|
password.len = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user