From 232372fd9660306a665f9eff4cb35f5b5b6e6dbe Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 15 Aug 2022 18:53:25 +0200 Subject: [PATCH] more defensive buffer handling --- .../PlocSupervisorDefinitions.h | 7 ------- linux/devices/ploc/PlocMPSoCHandler.cpp | 4 ++-- linux/devices/ploc/PlocMPSoCHelper.cpp | 3 +++ linux/devices/ploc/PlocSupervisorHandler.cpp | 1 - linux/devices/ploc/PlocSupvHelper.cpp | 16 ++++++++++++---- linux/devices/ploc/PlocSupvHelper.h | 2 ++ 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index d8c0d515..0b3ef03a 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -159,13 +159,6 @@ static const size_t MAX_PACKET_SIZE = 1024; static const uint8_t SPACE_PACKET_HEADER_LENGTH = 6; -// enum class SequenceFlags : uint8_t { -// CONTINUED_PKT = 0b00, -// FIRST_PKT = 0b01, -// LAST_PKT = 0b10, -// STANDALONE_PKT = 0b11 -// }; - enum PoolIds : lp_id_t { NUM_TMS, TEMP_PS, diff --git a/linux/devices/ploc/PlocMPSoCHandler.cpp b/linux/devices/ploc/PlocMPSoCHandler.cpp index 9df54ed2..b3eea536 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.cpp +++ b/linux/devices/ploc/PlocMPSoCHandler.cpp @@ -19,6 +19,8 @@ PlocMPSoCHandler::PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); commandActionHelperQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); + spParams.maxSize = sizeof(commandBuffer); + spParams.buf = commandBuffer; } PlocMPSoCHandler::~PlocMPSoCHandler() {} @@ -207,8 +209,6 @@ ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(DeviceCommandId_t device const uint8_t* commandData, size_t commandDataLen) { spParams.buf = commandBuffer; - spParams.maxSize = sizeof(commandBuffer); - ReturnValue_t result = RETURN_OK; switch (deviceCommand) { case (mpsoc::TC_MEM_WRITE): { diff --git a/linux/devices/ploc/PlocMPSoCHelper.cpp b/linux/devices/ploc/PlocMPSoCHelper.cpp index 9156138e..e9a65d64 100644 --- a/linux/devices/ploc/PlocMPSoCHelper.cpp +++ b/linux/devices/ploc/PlocMPSoCHelper.cpp @@ -104,6 +104,7 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string ReturnValue_t PlocMPSoCHelper::resetHelper() { ReturnValue_t result = RETURN_OK; semaphore.release(); + spParams.buf = commandBuffer; terminate = false; result = uartComIF->flushUartRxBuffer(comCookie); return result; @@ -162,6 +163,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() { ReturnValue_t PlocMPSoCHelper::flashfopen() { ReturnValue_t result = RETURN_OK; + spParams.buf = commandBuffer; (*sequenceCount)++; mpsoc::FlashFopen flashFopen(spParams, *sequenceCount); result = flashFopen.createPacket(flashWrite.mpsocFile, mpsoc::FlashFopen::APPEND); @@ -177,6 +179,7 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() { ReturnValue_t PlocMPSoCHelper::flashfclose() { ReturnValue_t result = RETURN_OK; + spParams.buf = commandBuffer; (*sequenceCount)++; mpsoc::FlashFclose flashFclose(spParams, *sequenceCount); result = flashFclose.createPacket(flashWrite.mpsocFile); diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 2b6c44d3..6cd8b656 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -201,7 +201,6 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d using namespace supv; ReturnValue_t result = RETURN_FAILED; spParams.buf = commandBuffer; - spParams.maxSize = sizeof(commandBuffer); switch (deviceCommand) { case GET_HK_REPORT: { prepareEmptyCmd(APID_GET_HK_REPORT); diff --git a/linux/devices/ploc/PlocSupvHelper.cpp b/linux/devices/ploc/PlocSupvHelper.cpp index 54e7c8ba..25566b11 100644 --- a/linux/devices/ploc/PlocSupvHelper.cpp +++ b/linux/devices/ploc/PlocSupvHelper.cpp @@ -17,8 +17,8 @@ #include "mission/utility/Timestamp.h" PlocSupvHelper::PlocSupvHelper(object_id_t objectId) : SystemObject(objectId) { - spParams.buf = commandBuffer; spParams.maxSize = sizeof(commandBuffer); + resetSpParams(); } PlocSupvHelper::~PlocSupvHelper() {} @@ -244,6 +244,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() { } else { seqFlags = ccsds::SequenceFlags::CONTINUATION; } + resetSpParams(); supv::WriteMemory packet(spParams); result = packet.buildPacket(seqFlags, update.sequenceCount++, update.memoryId, update.startAddress + update.bytesWritten, dataLength, tempData); @@ -271,6 +272,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() { ReturnValue_t PlocSupvHelper::performEventBufferRequest() { using namespace supv; ReturnValue_t result = RETURN_OK; + resetSpParams(); RequestLoggingData packet(spParams); result = packet.buildPacket(RequestLoggingData::Sa::REQUEST_EVENT_BUFFERS); if (result != RETURN_OK) { @@ -297,6 +299,7 @@ ReturnValue_t PlocSupvHelper::performEventBufferRequest() { ReturnValue_t PlocSupvHelper::selectMemory() { ReturnValue_t result = RETURN_OK; + resetSpParams(); supv::MPSoCBootSelect packet(spParams); result = packet.buildPacket(update.memoryId); if (result != RETURN_OK) { @@ -311,6 +314,7 @@ ReturnValue_t PlocSupvHelper::selectMemory() { ReturnValue_t PlocSupvHelper::prepareUpdate() { ReturnValue_t result = RETURN_OK; + resetSpParams(); supv::ApidOnlyPacket packet(spParams, supv::APID_PREPARE_UPDATE); result = packet.buildPacket(); result = handlePacketTransmission(packet, PREPARE_UPDATE_EXECUTION_REPORT); @@ -322,6 +326,7 @@ ReturnValue_t PlocSupvHelper::prepareUpdate() { ReturnValue_t PlocSupvHelper::eraseMemory() { ReturnValue_t result = RETURN_OK; + resetSpParams(); supv::EraseMemory eraseMemory(spParams); result = eraseMemory.buildPacket(update.memoryId, update.startAddress, update.length); if (result != RETURN_OK) { @@ -376,7 +381,7 @@ ReturnValue_t PlocSupvHelper::handleAck() { } supv::AcknowledgmentReport ackReport(tmBuf.data(), tmBuf.size()); result = checkReceivedTm(ackReport); - if(result != RETURN_OK) { + if (result != RETURN_OK) { return result; } result = ackReport.checkApid(); @@ -403,7 +408,7 @@ ReturnValue_t PlocSupvHelper::handleExe(uint32_t timeout) { } supv::ExecutionReport exeReport(tmBuf.data(), tmBuf.size()); result = checkReceivedTm(exeReport); - if(result != RETURN_OK) { + if (result != RETURN_OK) { return result; } result = exeReport.checkApid(); @@ -516,6 +521,7 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() { ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() { ReturnValue_t result = RETURN_OK; + resetSpParams(); // Verification of update write procedure supv::CheckMemory packet(spParams); result = packet.buildPacket(update.memoryId, update.startAddress, update.length); @@ -597,7 +603,7 @@ ReturnValue_t PlocSupvHelper::handleEventBufferReception() { return result; } ReturnValue_t result = tmReader.checkCrc(); - if(result != RETURN_OK) { + if (result != RETURN_OK) { triggerEvent(SUPV_REPLY_CRC_MISSMATCH, rememberApid); return result; } @@ -613,3 +619,5 @@ ReturnValue_t PlocSupvHelper::handleEventBufferReception() { } return result; } + +void PlocSupvHelper::resetSpParams() { spParams.buf = commandBuffer; } diff --git a/linux/devices/ploc/PlocSupvHelper.h b/linux/devices/ploc/PlocSupvHelper.h index 9531c3cb..c17521d9 100644 --- a/linux/devices/ploc/PlocSupvHelper.h +++ b/linux/devices/ploc/PlocSupvHelper.h @@ -244,6 +244,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha */ uint32_t getFileSize(std::string filename); ReturnValue_t handleEventBufferReception(); + + void resetSpParams(); }; #endif /* BSP_Q7S_DEVICES_PLOCSUPVHELPER_H_ */