From 5927dade4d5036082300394220fbee5c7e59bdff Mon Sep 17 00:00:00 2001 From: mariusmonton Date: Sun, 21 Feb 2021 13:47:06 +0100 Subject: [PATCH] check memory boundaries --- src/Memory.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Memory.cpp b/src/Memory.cpp index b652ad8..1cdcdda 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -114,6 +114,7 @@ bool Memory::get_direct_mem_ptr(tlm::tlm_generic_payload &trans, return false; } + // Permit read and write access dmi_data.allow_read_write(); @@ -133,6 +134,11 @@ unsigned int Memory::transport_dbg(tlm::tlm_generic_payload &trans) { unsigned char *ptr = trans.get_data_ptr(); unsigned int len = trans.get_data_length(); + if (adr >= sc_dt::uint64(SIZE)) { + trans.set_response_status(tlm::TLM_ADDRESS_ERROR_RESPONSE); + return 0; + } + // Calculate the number of bytes to be actually copied unsigned int num_bytes = (len < (SIZE - adr) * 4) ? len : (SIZE - adr) * 4;