From ee21c305f3f00e33d9bd82f7a56db45660178877 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 18 Oct 2023 16:18:35 -0400 Subject: [PATCH] Fix #121, add extra range checking Adds additional range checks to avoid out-of-bounds array access --- fsw/src/sc_atsrq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fsw/src/sc_atsrq.c b/fsw/src/sc_atsrq.c index 16ee96f..a826639 100644 --- a/fsw/src/sc_atsrq.c +++ b/fsw/src/sc_atsrq.c @@ -211,6 +211,12 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) { /* first get the cmd index at this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); + if (!SC_AtsCommandIndexIsValid(CmdIndex)) + { + SC_IDX_INCREMENT(TimeIndex); + continue; + } + /* then get the entry index from the cmd index table */ CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */ @@ -540,6 +546,12 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) { /* first get the cmd index at this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); + if (!SC_AtsCommandIndexIsValid(CmdIndex)) + { + SC_IDX_INCREMENT(TimeIndex); + continue; + } + /* then get the entry index from the cmd index table */ CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */