Skip to content

Commit 88b000f

Browse files
authored
Merge pull request #5996 from anecdata/channel_validate
WiFi Monitor: improve channel validation
2 parents da035fe + ffc217e commit 88b000f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

shared-bindings/wifi/Monitor.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ STATIC mp_obj_t wifi_monitor_make_new(const mp_obj_type_t *type, size_t n_args,
5555
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
5656
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
5757

58-
if (args[ARG_channel].u_int < 0 || args[ARG_channel].u_int > 13) {
58+
if (args[ARG_channel].u_int < 1 || args[ARG_channel].u_int > 13) {
5959
mp_raise_ValueError_varg(translate("%q out of bounds"), MP_QSTR_channel);
6060
}
6161

@@ -83,7 +83,11 @@ STATIC mp_obj_t wifi_monitor_obj_get_channel(mp_obj_t self_in) {
8383
MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_get_channel_obj, wifi_monitor_obj_get_channel);
8484

8585
STATIC mp_obj_t wifi_monitor_obj_set_channel(mp_obj_t self_in, mp_obj_t channel) {
86-
common_hal_wifi_monitor_set_channel(self_in, mp_obj_get_int(channel));
86+
mp_int_t c = mp_obj_get_int(channel);
87+
if (c < 1 || c > 13) {
88+
mp_raise_ValueError_varg(translate("%q out of bounds"), MP_QSTR_channel);
89+
}
90+
common_hal_wifi_monitor_set_channel(self_in, c);
8791
return mp_const_none;
8892
}
8993
MP_DEFINE_CONST_FUN_OBJ_2(wifi_monitor_set_channel_obj, wifi_monitor_obj_set_channel);

0 commit comments

Comments
 (0)