From ec20b7ed9d7886b26ea0431a40eee6b06d384f53 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 10 Dec 2020 17:58:02 -0800 Subject: [PATCH] validate flash request --- firmware/bootloader/bootloader.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/firmware/bootloader/bootloader.cpp b/firmware/bootloader/bootloader.cpp index d018331..2abdecf 100644 --- a/firmware/bootloader/bootloader.cpp +++ b/firmware/bootloader/bootloader.cpp @@ -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"