From f108c63c5a1075394cc2e36496a0ffc4488a4b04 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 0a15021..ad6a575 100644 --- a/fsw/src/sc_atsrq.c +++ b/fsw/src/sc_atsrq.c @@ -210,6 +210,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 */ @@ -538,6 +544,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 */