added check to avoid seg fault

This commit is contained in:
Robin Müller 2021-09-09 00:02:17 +02:00
parent 29abef40a4
commit b5063117f6
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 12 additions and 10 deletions

View File

@ -10,12 +10,10 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
size_t* encodedLen, bool addStxEtx) {
size_t minAllowedLen = 0;
if(escapeStxEtx) {
minAllowedLen = 2;
minAllowedLen = 1;
}
else {
minAllowedLen = 1;
minAllowedLen = 2;
}
if(maxDestLen < minAllowedLen) {
return STREAM_TOO_SHORT;
@ -41,7 +39,7 @@ ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx) {
size_t encodedIndex = 2;
size_t encodedIndex = 1;
size_t sourceIndex = 0;
uint8_t nextByte = 0;
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
@ -99,7 +97,7 @@ ReturnValue_t DleEncoder::encodeStreamEscaped(const uint8_t *sourceStream, size_
ReturnValue_t DleEncoder::encodeStreamNonEscaped(const uint8_t *sourceStream, size_t sourceLen,
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
bool addStxEtx) {
size_t encodedIndex = 1;
size_t encodedIndex = 2;
size_t sourceIndex = 0;
uint8_t nextByte = 0;
while (encodedIndex < maxDestLen and sourceIndex < sourceLen) {
@ -166,10 +164,14 @@ ReturnValue_t DleEncoder::decodeStreamEscaped(const uint8_t *sourceStream, size_
size_t encodedIndex = 1;
size_t decodedIndex = 0;
uint8_t nextByte;
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)
&& (sourceStream[encodedIndex] != ETX_CHAR)
&& (sourceStream[encodedIndex] != STX_CHAR)) {
while ((encodedIndex < sourceStreamLen)
and (decodedIndex < maxDestStreamlen)
and (sourceStream[encodedIndex] != ETX_CHAR)
and (sourceStream[encodedIndex] != STX_CHAR)) {
if (sourceStream[encodedIndex] == DLE_CHAR) {
if(encodedIndex + 1 >= sourceStreamLen) {
return DECODING_ERROR;
}
nextByte = sourceStream[encodedIndex + 1];
// The next byte is a DLE character that was escaped by another
// DLE character, so we can write it to the destination stream.

View File

@ -1,7 +1,7 @@
#ifndef FSFW_CATCHFACTORY_H_
#define FSFW_CATCHFACTORY_H_
#include "TestConfig.h"
#include "TestsConfig.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/objectmanager/ObjectManager.h"