alarm: validate epoch_time type in TimeAlarm constructor - #11318
Open
4RH1T3CT0R7 wants to merge 1 commit into
Open
alarm: validate epoch_time type in TimeAlarm constructor#113184RH1T3CT0R7 wants to merge 1 commit into
4RH1T3CT0R7 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Passing a non-int to
alarm.time.TimeAlarm(epoch_time=...), for example thestruct_timereturned bytime.localtime(), hard faults the board and drops it into safe mode. The constructor hands the object straight tomp_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 raisesTypeError: epoch_time must be of type int, not struct_timeinstead. Themonotonic_timepath already goes throughmp_obj_get_float(), which type-checks, so it is unchanged. There is no unix build ofalarm, so this is reasoned rather than tested on hardware.Fixes #11158