Merge pull request #5996 from anecdata/channel_validate

WiFi Monitor: improve channel validation
This commit is contained in:
Scott Shawcroft 2022-02-09 11:01:14 -08:00 committed by GitHub
commit 88b000f739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -55,7 +55,7 @@ STATIC mp_obj_t wifi_monitor_make_new(const mp_obj_type_t *type, size_t n_args,
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
if (args[ARG_channel].u_int < 0 || args[ARG_channel].u_int > 13) {
if (args[ARG_channel].u_int < 1 || args[ARG_channel].u_int > 13) {
mp_raise_ValueError_varg(translate("%q out of bounds"), MP_QSTR_channel);
}
@ -83,7 +83,11 @@ STATIC mp_obj_t wifi_monitor_obj_get_channel(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_get_channel_obj, wifi_monitor_obj_get_channel);
STATIC mp_obj_t wifi_monitor_obj_set_channel(mp_obj_t self_in, mp_obj_t channel) {
common_hal_wifi_monitor_set_channel(self_in, mp_obj_get_int(channel));
mp_int_t c = mp_obj_get_int(channel);
if (c < 1 || c > 13) {
mp_raise_ValueError_varg(translate("%q out of bounds"), MP_QSTR_channel);
}
common_hal_wifi_monitor_set_channel(self_in, c);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(wifi_monitor_set_channel_obj, wifi_monitor_obj_set_channel);