validate flash request

This commit is contained in:
Matthew Kennedy 2020-12-10 17:58:02 -08:00
parent a418c9903f
commit ec20b7ed9d
1 changed files with 10 additions and 1 deletions

View File

@ -151,7 +151,16 @@ void RunBootloaderLoop()
case 0x02: // opcode 2 is "write flash data"
// Embedded data is the flash address
Flash::Write(appFlashAddr + embeddedData, &frame.data8[0], frame.DLC);
// Don't allow misaligned writes
if (embeddedData % sizeof(flashdata_t) != 0 || frame.DLC % sizeof(flashdata_t) != 0)
{
sendNak();
}
else
{
Flash::Write(appFlashAddr + embeddedData, &frame.data8[0], frame.DLC);
sendAck();
}
break;
case 0x03: // opcode 3 is "boot app"