From 2c19f4f898c4db7b5e1dae811d5dec22fbc150e2 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:14:28 -0600 Subject: [PATCH 1/3] improve channel validation --- shared-bindings/wifi/Monitor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shared-bindings/wifi/Monitor.c b/shared-bindings/wifi/Monitor.c index a9998e7410..005c91eeaa 100644 --- a/shared-bindings/wifi/Monitor.c +++ b/shared-bindings/wifi/Monitor.c @@ -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("%d out of bounds"), c); + } + 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); From 7411f0ca8182e2569d35bdcaafb5b7ad4f6d387a Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:23:18 -0600 Subject: [PATCH 2/3] translate --- locale/circuitpython.pot | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 3603079e8e..c48064e269 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -156,6 +156,10 @@ msgstr "" msgid "%q out of bounds" msgstr "" +#: shared-bindings/wifi/Monitor.c +msgid "%d out of bounds" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/canio/Match.c msgid "%q out of range" From ffc217e468bedf10981f183dde0546a03eeb496e Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:55:44 -0600 Subject: [PATCH 3/3] consolidate exception strings --- locale/circuitpython.pot | 4 ---- shared-bindings/wifi/Monitor.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index c48064e269..3603079e8e 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -156,10 +156,6 @@ msgstr "" msgid "%q out of bounds" msgstr "" -#: shared-bindings/wifi/Monitor.c -msgid "%d out of bounds" -msgstr "" - #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/canio/Match.c msgid "%q out of range" diff --git a/shared-bindings/wifi/Monitor.c b/shared-bindings/wifi/Monitor.c index 005c91eeaa..4e5235ea88 100644 --- a/shared-bindings/wifi/Monitor.c +++ b/shared-bindings/wifi/Monitor.c @@ -85,7 +85,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_get_channel_obj, wifi_monitor_obj_get_cha STATIC mp_obj_t wifi_monitor_obj_set_channel(mp_obj_t self_in, mp_obj_t channel) { mp_int_t c = mp_obj_get_int(channel); if (c < 1 || c > 13) { - mp_raise_ValueError_varg(translate("%d out of bounds"), c); + 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;