Added memory address and type validation in GDB memory access command packets (fixes https://github.com/navnavnav/Bloom/issues/37)

This commit is contained in:
Nav
2022-05-04 19:57:41 +01:00
parent 38f6f21627
commit 7b25fa4b5c
2 changed files with 64 additions and 0 deletions

View File

@@ -72,12 +72,34 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
Logger::debug("Handling WriteMemory packet");
try {
const auto& memoryDescriptorsByType = debugSession.gdbTargetDescriptor.targetDescriptor.memoryDescriptorsByType;
if (!memoryDescriptorsByType.contains(this->memoryType)) {
throw Exception("Target does not support the requested memory type.");
}
if (this->memoryType == Targets::TargetMemoryType::FLASH) {
throw Exception(
"GDB client requested a flash memory write - This is not currently supported by Bloom."
);
}
if (this->buffer.size() == 0) {
debugSession.connection.writePacket(OkResponsePacket());
return;
}
const auto& memoryDescriptor = memoryDescriptorsByType.at(this->memoryType);
if (
this->startAddress < memoryDescriptor.addressRange.startAddress
|| (this->startAddress + (this->buffer.size() - 1)) > memoryDescriptor.addressRange.endAddress
) {
throw Exception(
"GDB requested access to memory which is outside the target's memory range"
);
}
targetControllerConsole.writeMemory(
this->memoryType,
this->startAddress,