From d17146d847610b403118c7992908a94deb361e1c Mon Sep 17 00:00:00 2001 From: Maximilian Luz Date: Thu, 19 Dec 2019 16:09:50 +0100 Subject: [PATCH] Check object existence before adding it to the PST Currently, adding new objects/components to the FixedSlotSequence PST is not being checked, meaning that it is possible to add NULL objects here without any warning. This causes NULL-pointer errors when non-existent components are added, which can be hard to debug. To solve this, add a check for the object existence before adding it to PST and emit an error message. Signed-off-by: Maximilian Luz --- osal/FreeRTOS/FixedTimeslotTask.cpp | 5 +++++ osal/linux/FixedTimeslotTask.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 5bf09f13..4a30774a 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -57,6 +57,11 @@ ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { + if (!objectManager->get(componentId)) { + error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; } diff --git a/osal/linux/FixedTimeslotTask.cpp b/osal/linux/FixedTimeslotTask.cpp index 99cbf818..21040e6e 100644 --- a/osal/linux/FixedTimeslotTask.cpp +++ b/osal/linux/FixedTimeslotTask.cpp @@ -40,6 +40,11 @@ uint32_t FixedTimeslotTask::getPeriodMs() const { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { + if (!objectManager->get(componentId)) { + error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; }