Skip to content

Emulator Can Access Unallocated Memory Through Banks 6 and 7 #80

@Elelzedel

Description

@Elelzedel

Description
memoryBytes is allocated with 6 banks:

memoryBytes = vector<vector<uint16_t>>(6, vector<uint16_t>(65535, 0));

However, each of the instructions capable of updating the bank register limit the register range with this code:

BankReg = arg & 0b111;

This limits BankReg to values between 0 and 7, but only 0 to 5 are allocated.

Steps to Reproduce

  1. Create an Astrisc program with the following code which attempts to write 65 to bank 6 at word 50000.
LDIA 65
STLGE 6
HERE 50000
  1. Run this program in a debugger (this was tested on GDB in Debian), and observe that it crashes with a segmentation fault at SetMem(bank = 6, address = 50000, data=65).

Expected behavior
From the Memory Layout documentation, it appears only banks 0, 1, and 2 should be valid. Perhaps only 3 banks should be allocated and BankReg be instead limited to those 3 banks? Either way, the issue here is simply that Astro-8 programs can perform out-of-bounds writes, so each instance where the emulator updates BankReg should perform a limit check that matches the number of "rows" allocated by:

memoryBytes = vector<vector<uint16_t>>(6, vector<uint16_t>(65535, 0));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions