diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-10-09 21:45:05 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-10-09 21:45:05 +0200 |
| commit | f6df4314945c1d37d314a7c88553b97b23c748e9 (patch) | |
| tree | 20e71c89c25f469a83c52528dfdfe0ed71a8c3e1 /tests | |
| parent | aa5174fc055dc66e78a8aa7030c018e43cf588a1 (diff) | |
| download | tools.nes-f6df4314945c1d37d314a7c88553b97b23c748e9.tar.gz tools.nes-f6df4314945c1d37d314a7c88553b97b23c748e9.zip | |
vnf,runrom: detect bad data access
This includes detection for:
- Stack underflows (it was theoretically already there but it had never
been properly tested).
- Load/store out of bounds for a given variable known via the .nasm/
directory.
- Load out of bounds on a set of data referenced via a raw label (see
commit aa5174fc055d ("xixanta: Add an hint for the ending of data
labels")).
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/expected/runrom/overflow-arithmetics.txt | 6 | ||||
| -rw-r--r-- | tests/expected/runrom/overflow-data-indexing.txt | 10 | ||||
| -rw-r--r-- | tests/expected/runrom/overflow-reset.txt | 8 | ||||
| -rw-r--r-- | tests/expected/runrom/overflow-stack.txt | 6 | ||||
| -rw-r--r-- | tests/runrom/overflows.s | 72 |
5 files changed, 102 insertions, 0 deletions
diff --git a/tests/expected/runrom/overflow-arithmetics.txt b/tests/expected/runrom/overflow-arithmetics.txt new file mode 100644 index 0000000..3eadfae --- /dev/null +++ b/tests/expected/runrom/overflow-arithmetics.txt @@ -0,0 +1,6 @@ +<start> PC: $8011, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- +ldx #$01 PC: $8013, cycles: 9, registers: [a: $00, x: $01, y: $00, sp: $FD], status: ----I-- + +@: +lda $0F, x PC: $8013, cycles: 9, registers: [a: $00, x: $01, y: $00, sp: $FD], status: ----I-- +error: out of bounds: indexed access to $0010 falls out of 'zp_buffer' ($00-$10; bounded inclusively below and exclusively above) diff --git a/tests/expected/runrom/overflow-data-indexing.txt b/tests/expected/runrom/overflow-data-indexing.txt new file mode 100644 index 0000000..469a265 --- /dev/null +++ b/tests/expected/runrom/overflow-data-indexing.txt @@ -0,0 +1,10 @@ +<start> PC: $801B, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- +ldx #$00 PC: $801D, cycles: 9, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +lda $8028, x PC: $8020, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +clc PC: $8021, cycles: 15, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +adc #$04 PC: $8023, cycles: 17, registers: [a: $04, x: $00, y: $00, sp: $FD], status: ----I-- +tax PC: $8024, cycles: 19, registers: [a: $04, x: $04, y: $00, sp: $FD], status: ----I-- + +@: +lda $8028, x PC: $8024, cycles: 19, registers: [a: $04, x: $04, y: $00, sp: $FD], status: ----I-- +error: out of bounds: indexed access to $802C falls out of 'bad_rom_data_indexing::data' ($8028-$802C; bounded inclusively below and exclusively above) diff --git a/tests/expected/runrom/overflow-reset.txt b/tests/expected/runrom/overflow-reset.txt new file mode 100644 index 0000000..6097a9c --- /dev/null +++ b/tests/expected/runrom/overflow-reset.txt @@ -0,0 +1,8 @@ +<start> PC: $8000, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- +ldx #$00 PC: $8002, cycles: 9, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +lda $00, x PC: $8004, cycles: 13, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- +dex PC: $8005, cycles: 15, registers: [a: $00, x: $FF, y: $00, sp: $FD], status: ----I-- + +@: +lda $00, x PC: $8005, cycles: 15, registers: [a: $00, x: $FF, y: $00, sp: $FD], status: ----I-- +error: out of bounds: indexed access to $00FF falls out of 'zp_buffer' ($00-$10; bounded inclusively below and exclusively above) diff --git a/tests/expected/runrom/overflow-stack.txt b/tests/expected/runrom/overflow-stack.txt new file mode 100644 index 0000000..3a00e0a --- /dev/null +++ b/tests/expected/runrom/overflow-stack.txt @@ -0,0 +1,6 @@ +<start> PC: $8016, cycles: 7, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----I-- +lda #$00 PC: $8018, cycles: 9, registers: [a: $00, x: $00, y: $00, sp: $FD], status: ----IZ- + +@: +pha PC: $8018, cycles: 9, registers: [a: $00, x: $00, y: $00, sp: $FC], status: ----IZ- +error: stack underflow! diff --git a/tests/runrom/overflows.s b/tests/runrom/overflows.s new file mode 100644 index 0000000..e2a5b47 --- /dev/null +++ b/tests/runrom/overflows.s @@ -0,0 +1,72 @@ +.segment "HEADER" + .byte 'N', 'E', 'S', $1A + .byte $02, $01 + .byte $00 + .byte $00 + +.segment "CHARS" +.byte 0 + +.segment "VECTORS" + .addr reset, reset, reset + +.segment "CODE" + +zp_buffer = $00 ; asan:reserve $10 + +.proc reset + ;; Fine. + ldx #0 + lda zp_buffer, x + + ;; NOTE: overflow! + dex + lda zp_buffer, x + + ;; Just so there are no "unused" warnings :) + jsr overflow_on_arithmetics + jsr stack_underflow + jsr bad_rom_data_indexing + + rts +.endproc + +.proc overflow_on_arithmetics + ;; NOTE: overflow! + ;; NOTE: another overflow scenario could be 'lda zp_buffer + 16, x', but + ;; 'nasm' can statically point this out and it will throw an error. + ldx #1 + lda zp_buffer + 15, x + + rts +.endproc + +;; asan:stack $FD-$FF +.proc stack_underflow + lda #0 + + ;; NOTE: stack underflow! + pha + pla + + rts +.endproc + +.proc bad_rom_data_indexing + ;; Fine. + ldx #0 + lda data, x + + clc + adc #4 + tax + + ;; NOTE: overflow! + lda data, x + + rts +data: + .byte $00, $01, $02, $03 + + lda zp_buffer +.endproc |
