Repository navigation
Fix two UBSan reports: MCU name lookup past the names array, negative left shift in BRBS/BRBC - #594
Merged
Merged
Conversation
… left shift in BRBS/BRBC avr_make_mcu_by_name stops at a NULL alias, but a core that fills all 4 names slots has none, so the loop read past the array. Bound it by the array's size. BRBS/BRBC computed the target as new_pc + (o << 1) with a negative offset, a left shift of a negative value (undefined behaviour); o * 2 is the same without it.
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.
Building simavr with
-fsanitize=address,undefinedreports two spots:sim_avr.c:runtime error: index 4 out of bounds for type 'const char *[4]'inavr_make_mcu_by_name. The inner loop stops at a NULL alias, but a core that fills all 4namesslots has none, so it reads past the array. The loop is now bounded byARRAY_SIZE(names)as well.sim_core.c:runtime error: left shift of negative value -2in BRBS/BRBC:new_pc + (o << 1)with a negative offset.o * 2gives the same target without the undefined behaviour.No change in behaviour on the compilers I tried; it lets simavr run under the sanitizers cleanly. We carry it as a patch on v1.8 and ran our simavr-driven test suite (ASan + UBSan, simavr instrumented) with it.