From fee9f577a12da67a577d9351f9469cb01c0d00db Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 16 Jan 2023 16:40:03 -0500 Subject: [PATCH] Fix #66, correct buffer overflows in UT The default size of the "EventText" string is 32, but the unit test had hard coded string sizes of 50 chars, which will overflow the buffer. Use "sizeof" operator to adjust to the actual size of the destination to correct the issue. --- unit-test/lc_action_tests.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unit-test/lc_action_tests.c b/unit-test/lc_action_tests.c index ada0b8b..36056d4 100644 --- a/unit-test/lc_action_tests.c +++ b/unit-test/lc_action_tests.c @@ -230,7 +230,7 @@ void LC_SampleSingleAP_Test_ActiveRequestRTS(void) LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS = 5; LC_OperData.ARTPtr[APNumber].ConsecutiveFailCount = LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS; - strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", 50); + strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", sizeof(LC_OperData.ADTPtr[APNumber].EventText)); /* Execute the function being tested */ LC_SampleSingleAP(APNumber); @@ -274,7 +274,7 @@ void LC_SampleSingleAP_Test_APFailWhileLCStatePassive(void) LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS = 5; LC_OperData.ARTPtr[APNumber].ConsecutiveFailCount = LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS; - strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", 50); + strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", sizeof(LC_OperData.ADTPtr[APNumber].EventText)); /* Execute the function being tested */ LC_SampleSingleAP(APNumber); @@ -318,7 +318,7 @@ void LC_SampleSingleAP_Test_APFailWhilePassive(void) LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS = 5; LC_OperData.ARTPtr[APNumber].ConsecutiveFailCount = LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS; - strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", 50); + strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", sizeof(LC_OperData.ADTPtr[APNumber].EventText)); LC_OperData.ADTPtr[APNumber].MaxPassiveEvents = 5; LC_OperData.ARTPtr[APNumber].PassiveAPCount = LC_OperData.ADTPtr[APNumber].MaxPassiveEvents - 1; @@ -363,7 +363,7 @@ void LC_SampleSingleAP_Test_APFailWhilePassiveNoEvent(void) LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS = 5; LC_OperData.ARTPtr[APNumber].ConsecutiveFailCount = LC_OperData.ADTPtr[APNumber].MaxFailsBeforeRTS; - strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", 50); + strncpy(LC_OperData.ADTPtr[APNumber].EventText, "Event Message", sizeof(LC_OperData.ADTPtr[APNumber].EventText)); LC_OperData.ADTPtr[APNumber].MaxPassiveEvents = 5; LC_OperData.ARTPtr[APNumber].PassiveAPCount = LC_OperData.ADTPtr[APNumber].MaxPassiveEvents + 1;