Permitted GDB to read two bytes above the end address of SRAM

This commit is contained in:
Nav
2022-05-14 22:44:26 +01:00
parent 72b3d271a2
commit 4ab955a6f7

View File

@@ -79,13 +79,15 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
* In AVR targets, RAM is mapped to many registers and peripherals - we don't want to block GDB from * In AVR targets, RAM is mapped to many registers and peripherals - we don't want to block GDB from
* accessing them. * accessing them.
*/ */
const auto memoryStartAddress = (this->memoryType == Targets::TargetMemoryType::RAM) const auto permittedStartAddress = (this->memoryType == Targets::TargetMemoryType::RAM)
? 0x00 ? 0x00
: memoryDescriptor.addressRange.startAddress; : memoryDescriptor.addressRange.startAddress;
const auto permittedEndAddress = memoryDescriptor.addressRange.endAddress + 2;
if ( if (
this->startAddress < memoryStartAddress this->startAddress < permittedStartAddress
|| (this->startAddress + (this->bytes - 1)) > memoryDescriptor.addressRange.endAddress || (this->startAddress + (this->bytes - 1)) > permittedEndAddress
) { ) {
/* /*
* GDB can be configured to generate backtraces past the main function and the internal entry point * GDB can be configured to generate backtraces past the main function and the internal entry point
@@ -110,11 +112,24 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
return; return;
} }
auto memoryBuffer = targetControllerConsole.readMemory( const auto bytesToRead = (this->startAddress <= memoryDescriptor.addressRange.endAddress)
? std::min(this->bytes, (memoryDescriptor.addressRange.endAddress - this->startAddress) + 1)
: 0;
auto memoryBuffer = Targets::TargetMemoryBuffer();
if (bytesToRead > 0) {
memoryBuffer = targetControllerConsole.readMemory(
this->memoryType, this->memoryType,
this->startAddress, this->startAddress,
this->bytes bytesToRead
); );
}
if (bytesToRead < this->bytes) {
// GDB requested some out-of-bounds memory - fill the inaccessible bytes with 0s
memoryBuffer.insert(memoryBuffer.end(), (this->bytes - bytesToRead), 0x00);
}
debugSession.connection.writePacket( debugSession.connection.writePacket(
ResponsePacket(Packet::toHex(memoryBuffer)) ResponsePacket(Packet::toHex(memoryBuffer))