diff --git a/src/FOSSA-Comms.cpp b/src/FOSSA-Comms.cpp index b87215b..8dda65f 100644 --- a/src/FOSSA-Comms.cpp +++ b/src/FOSSA-Comms.cpp @@ -184,6 +184,14 @@ int16_t FCP_Get_OptData(char* callsign, uint8_t* frame, uint8_t frameLen, uint8_ uint8_t optDataLen = *framePtr; framePtr += 1; + // check that the declared length matches the number of bytes actually + // present in the frame, otherwise a malformed length byte would cause + // the memcpy below to overrun the caller's optData buffer (same check + // as FCP_Get_OptData_Length) + if(optDataLen != (uint8_t)(frameLen - strlen(callsign) - 2)) { + return(ERR_LENGTH_MISMATCH); + } + // get optional data memcpy(optData, framePtr, optDataLen); framePtr += optDataLen;