Skip to content

Commit c91ae4e

Browse files
committed
codal_port/microbit_microphone: Validate duration and rate args.
Signed-off-by: Damien George <[email protected]>
1 parent 6465bba commit c91ae4e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/codal_port/microbit_microphone.c

+8
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ static mp_obj_t microbit_microphone_record(mp_uint_t n_args, const mp_obj_t *pos
184184
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
185185
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
186186

187+
// Validate arguments.
188+
if (args[ARG_duration].u_int <= 0) {
189+
mp_raise_ValueError(MP_ERROR_TEXT("duration out of bounds"));
190+
}
191+
if (args[ARG_rate].u_int <= 0) {
192+
mp_raise_ValueError(MP_ERROR_TEXT("rate out of bounds"));
193+
}
194+
187195
// Create the AudioFrame to record into.
188196
size_t size = args[ARG_duration].u_int * args[ARG_rate].u_int / 1000;
189197
microbit_audio_frame_obj_t *audio_frame = microbit_audio_frame_make_new(size, args[ARG_rate].u_int);

0 commit comments

Comments
 (0)