From d4078afb0c4ce9efc884651b095d0396b2ee8316 Mon Sep 17 00:00:00 2001 From: Fabrizio Sandri Date: Mon, 13 Dec 2021 21:45:19 +0100 Subject: [PATCH 1/6] ObjBase snprintf fix --- Fw/Obj/ObjBase.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Fw/Obj/ObjBase.cpp b/Fw/Obj/ObjBase.cpp index 64ed422e6b..632863f999 100644 --- a/Fw/Obj/ObjBase.cpp +++ b/Fw/Obj/ObjBase.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -46,8 +47,10 @@ namespace Fw { } #if FW_OBJECT_TO_STRING == 1 void ObjBase::toString(char* str, NATIVE_INT_TYPE size) { - (void)snprintf(str, size, "Obj: %s",this->m_objName); - str[size-1] = 0; + FW_ASSERT(size > 0); + if (snprintf(str, size, "Obj: %s",this->m_objName) < 0) { + str[0] = 0; + } } #endif #endif From f16c778a18102cc8b1f922735d54274a3ea31239 Mon Sep 17 00:00:00 2001 From: Fabrizio Sandri Date: Mon, 13 Dec 2021 21:46:11 +0100 Subject: [PATCH 2/6] InputPortBase snprintf fix --- Fw/Port/InputPortBase.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Fw/Port/InputPortBase.cpp b/Fw/Port/InputPortBase.cpp index 55b7051086..4f8f6f87a1 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -29,10 +29,12 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) { -#if FW_OBJECT_NAMES == 1 - (void)snprintf(buffer, size, "InputPort: %s->%s", this->m_objName, - this->isConnected() ? this->m_connObj->getObjName() : "None"); - buffer[size-1] = 0; +#if FW_OBJECT_NAMES == 1 + FW_ASSERT(size > 0); + if (snprintf(buffer, size, "InputPort: %s->%s", this->m_objName, + this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { + buffer[0] = 0; + } #else (void)snprintf(buffer,size,"%s","Unnamed Input port"); #endif From 0f4a05a58833d818970b19e4dc15aaf7c82de7e9 Mon Sep 17 00:00:00 2001 From: Fabrizio Sandri Date: Mon, 13 Dec 2021 21:46:42 +0100 Subject: [PATCH 3/6] InputSerializePort snprintf fix --- Fw/Port/InputSerializePort.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Fw/Port/InputSerializePort.cpp b/Fw/Port/InputSerializePort.cpp index c374b0fb47..31d26473ef 100644 --- a/Fw/Port/InputSerializePort.cpp +++ b/Fw/Port/InputSerializePort.cpp @@ -38,10 +38,12 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 void InputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) { -#if FW_OBJECT_NAMES == 1 - (void)snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", - this->isConnected() ? this->m_connObj->getObjName() : "None"); - buffer[size-1] = 0; +#if FW_OBJECT_NAMES == 1 + FW_ASSERT(size > 0); + if (snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", + this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { + buffer[0] = 0; + } #else (void)snprintf(buffer,size,"%s","InputSerializePort"); #endif From e688234ee50ec9fdfcc109d9148de67de3da2430 Mon Sep 17 00:00:00 2001 From: Fabrizio Sandri Date: Mon, 13 Dec 2021 21:47:04 +0100 Subject: [PATCH 4/6] OutputPortBase snprintf fix --- Fw/Port/OutputPortBase.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Fw/Port/OutputPortBase.cpp b/Fw/Port/OutputPortBase.cpp index 5dd41b36e3..00497d0b4f 100644 --- a/Fw/Port/OutputPortBase.cpp +++ b/Fw/Port/OutputPortBase.cpp @@ -38,10 +38,12 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 void OutputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) { -#if FW_OBJECT_NAMES == 1 - (void)snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", - this->isConnected() ? this->m_connObj->getObjName() : "None"); - buffer[size-1] = 0; +#if FW_OBJECT_NAMES == 1 + FW_ASSERT(size > 0); + if (snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", + this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { + buffer[0] = 0; + } #else (void)snprintf(buffer,size,"%s","OutputPort"); #endif From e9c635823b5f0fee9ae809a060376d936c2abf75 Mon Sep 17 00:00:00 2001 From: Fabrizio Sandri Date: Mon, 13 Dec 2021 21:47:30 +0100 Subject: [PATCH 5/6] OutputSerializePort snprintf fix --- Fw/Port/OutputSerializePort.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Fw/Port/OutputSerializePort.cpp b/Fw/Port/OutputSerializePort.cpp index 2eb9a0f14e..dc7043486c 100644 --- a/Fw/Port/OutputSerializePort.cpp +++ b/Fw/Port/OutputSerializePort.cpp @@ -20,10 +20,12 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 void OutputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) { -#if FW_OBJECT_NAMES == 1 - (void)snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", - this->isConnected() ? this->m_connObj->getObjName() : "None"); - buffer[size-1] = 0; +#if FW_OBJECT_NAMES == 1 + FW_ASSERT(size > 0); + if (snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", + this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { + buffer[0] = 0; + } #else (void)snprintf(buffer,size,"%s","OutputSerializePort"); #endif From bc1e0fd4b98f589b4694bcc511a7f009f0678f34 Mon Sep 17 00:00:00 2001 From: Fabrizio Sandri Date: Mon, 13 Dec 2021 21:47:48 +0100 Subject: [PATCH 6/6] PortBase snprintf fix --- Fw/Port/PortBase.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Fw/Port/PortBase.cpp b/Fw/Port/PortBase.cpp index 2fdb010e4c..423e5d5234 100644 --- a/Fw/Port/PortBase.cpp +++ b/Fw/Port/PortBase.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "Fw/Types/Assert.hpp" #include #if FW_PORT_TRACING @@ -77,10 +78,11 @@ namespace Fw { #if FW_OBJECT_NAMES == 1 #if FW_OBJECT_TO_STRING == 1 void PortBase::toString(char* buffer, NATIVE_INT_TYPE size) { - (void)snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName, this->m_connObj ? "C" : "NC", - this->m_connObj ? this->m_connObj->getObjName() : "None"); - // NULL terminate - buffer[size-1] = 0; + FW_ASSERT(size > 0); + if (snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName, this->m_connObj ? "C" : "NC", + this->m_connObj ? this->m_connObj->getObjName() : "None") < 0) { + buffer[0] = 0; + } } #endif // FW_OBJECT_TO_STRING #endif // FW_OBJECT_NAMES