Skip to content

Fix two UBSan reports: MCU name lookup past the names array, negative left shift in BRBS/BRBC - #594

Merged
gatk555 merged 1 commit into
buserror:masterfrom
nyxaria:ubsan-fixes
Oct 12, 2026
Merged

gatk555 merged 1 commit into
buserror:masterfrom
nyxaria:ubsan-fixes

Conversation

@nyxaria

@nyxaria nyxaria commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Building simavr with -fsanitize=address,undefined reports two spots:

  • sim_avr.c: runtime error: index 4 out of bounds for type 'const char *[4]' in avr_make_mcu_by_name. The inner loop stops at a NULL alias, but a core that fills all 4 names slots has none, so it reads past the array. The loop is now bounded by ARRAY_SIZE(names) as well.
  • sim_core.c: runtime error: left shift of negative value -2 in BRBS/BRBC: new_pc + (o << 1) with a negative offset. o * 2 gives 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.

… 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.
@gatk555
gatk555 merged commit 557b074 into buserror:master Oct 12, 2026
8 checks passed
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.

2 participants