Skip to content

alarm: validate epoch_time type in TimeAlarm constructor - #11318

Open
4RH1T3CT0R7 wants to merge 1 commit into
adafruit:mainfrom
4RH1T3CT0R7:fix/timealarm-epoch-type-check
Open

alarm: validate epoch_time type in TimeAlarm constructor#11318
4RH1T3CT0R7 wants to merge 1 commit into
adafruit:mainfrom
4RH1T3CT0R7:fix/timealarm-epoch-type-check

Conversation

@4RH1T3CT0R7

Copy link
Copy Markdown

Passing a non-int to alarm.time.TimeAlarm(epoch_time=...), for example the struct_time returned by time.localtime(), hard faults the board and drops it into safe mode. The constructor hands the object straight to mp_obj_int_get_checked(), which assumes it is already an int and reads the object memory as one.

This switches the read to mp_arg_validate_type_int(), the helper the rest of shared-bindings uses for int arguments, so a wrong type raises TypeError: epoch_time must be of type int, not struct_time instead. The monotonic_time path already goes through mp_obj_get_float(), which type-checks, so it is unchanged. There is no unix build of alarm, so this is reasoned rather than tested on hardware.

Fixes #11158

mp_obj_int_get_checked() assumes its argument is already an int and
reads it as one. Passing anything else, such as the struct_time from
time.localtime(), dereferences garbage and hard faults the board.

Use mp_arg_validate_type_int() so a non-int raises TypeError naming the
argument, matching the other int arguments in shared-bindings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hard crash passing struct_time to alarm.time.TimeAlarm(epoch_time=xxx)

1 participant