removed unnecessary case and added more size checks

This commit is contained in:
Robin Müller 2020-07-10 20:31:10 +02:00
parent 3145036210
commit 444ee80f35
2 changed files with 16 additions and 19 deletions

View File

@ -60,13 +60,11 @@ ReturnValue_t Service2DeviceAccess::prepareCommand(CommandMessage* message,
uint32_t* state, object_id_t objectId) { uint32_t* state, object_id_t objectId) {
switch(static_cast<Subservice>(subservice)){ switch(static_cast<Subservice>(subservice)){
case Subservice::RAW_COMMANDING: { case Subservice::RAW_COMMANDING: {
return prepareRawCommand(dynamic_cast<CommandMessage*>(message), return prepareRawCommand(message, tcData, tcDataLen);
tcData, tcDataLen);
} }
break; break;
case Subservice::TOGGLE_WIRETAPPING: { case Subservice::TOGGLE_WIRETAPPING: {
return prepareWiretappingCommand(dynamic_cast<CommandMessage*>(message), return prepareWiretappingCommand(message, tcData, tcDataLen);
tcData, tcDataLen);
} }
break; break;
default: default:

View File

@ -7,9 +7,8 @@ PusParser::PusParser(uint16_t maxExpectedPusPackets,
ReturnValue_t PusParser::parsePusPackets(const uint8_t *frame, ReturnValue_t PusParser::parsePusPackets(const uint8_t *frame,
size_t frameSize) { size_t frameSize) {
if(frame == nullptr) { if(frame == nullptr or frameSize < 5) {
sif::error << "PusParser::parsePusPackets: Frame pointers in invalid!" sif::error << "PusParser::parsePusPackets: Frame invalid!" << std::endl;
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -25,15 +24,13 @@ ReturnValue_t PusParser::parsePusPackets(const uint8_t *frame,
} }
size_t packetSize = lengthField + 7; size_t packetSize = lengthField + 7;
// sif::debug << frameSize << std::endl;
// Size of a pus packet is the value in the packet length field plus 7. // Size of a pus packet is the value in the packet length field plus 7.
if(packetSize > frameSize) if(packetSize > frameSize) {
{ if(storeSplitPackets) {
if(storeSplitPackets)
{
indexSizePairFIFO.insert(indexSizePair(0, frameSize)); indexSizePairFIFO.insert(indexSizePair(0, frameSize));
} }
else else {
{
sif::debug << "TcSerialPollingTask::readNextPacket: Next packet " sif::debug << "TcSerialPollingTask::readNextPacket: Next packet "
"larger than remaining frame," << std::endl; "larger than remaining frame," << std::endl;
sif::debug << "Throwing away packet. Detected packet size: " sif::debug << "Throwing away packet. Detected packet size: "
@ -41,8 +38,7 @@ ReturnValue_t PusParser::parsePusPackets(const uint8_t *frame,
} }
return SPLIT_PACKET; return SPLIT_PACKET;
} }
else else {
{
indexSizePairFIFO.insert(indexSizePair(0, packetSize)); indexSizePairFIFO.insert(indexSizePair(0, packetSize));
if(packetSize == frameSize) { if(packetSize == frameSize) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
@ -77,6 +73,11 @@ PusParser::indexSizePair PusParser::getNextFifoPair() {
ReturnValue_t PusParser::readNextPacket(const uint8_t *frame, ReturnValue_t PusParser::readNextPacket(const uint8_t *frame,
size_t frameSize, size_t& currentIndex) { size_t frameSize, size_t& currentIndex) {
// sif::debug << startIndex << std::endl; // sif::debug << startIndex << std::endl;
if(currentIndex + 5 > frameSize) {
currentIndex = frameSize;
return HasReturnvaluesIF::RETURN_OK;
}
uint16_t lengthField = frame[currentIndex + 4] << 8 | uint16_t lengthField = frame[currentIndex + 4] << 8 |
frame[currentIndex + 5]; frame[currentIndex + 5];
if(lengthField == 0) { if(lengthField == 0) {
@ -88,12 +89,10 @@ ReturnValue_t PusParser::readNextPacket(const uint8_t *frame,
size_t remainingSize = frameSize - currentIndex; size_t remainingSize = frameSize - currentIndex;
if(nextPacketSize > remainingSize) if(nextPacketSize > remainingSize)
{ {
if(storeSplitPackets) if(storeSplitPackets) {
{
indexSizePairFIFO.insert(indexSizePair(currentIndex, remainingSize)); indexSizePairFIFO.insert(indexSizePair(currentIndex, remainingSize));
} }
else else {
{
sif::debug << "TcSerialPollingTask::readNextPacket: Next packet " sif::debug << "TcSerialPollingTask::readNextPacket: Next packet "
"larger than remaining frame," << std::endl; "larger than remaining frame," << std::endl;
sif::debug << "Throwing away packet. Detected packet size: " sif::debug << "Throwing away packet. Detected packet size: "