better size checks
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
This commit is contained in:
@ -1101,7 +1101,7 @@ class WriteMemory : public ploc::SpTcBase {
|
||||
static const uint16_t META_DATA_LENGTH = 8;
|
||||
uint8_t n = 1;
|
||||
|
||||
void initPacket(uint8_t memoryId, uint32_t startAddr, uint16_t updateDataLen,
|
||||
ReturnValue_t initPacket(uint8_t memoryId, uint32_t startAddr, uint16_t updateDataLen,
|
||||
uint8_t* updateData) {
|
||||
size_t serializedSize = 0;
|
||||
uint8_t* data = payloadStart;
|
||||
@ -1113,7 +1113,6 @@ class WriteMemory : public ploc::SpTcBase {
|
||||
SerializeIF::Endianness::BIG);
|
||||
SerializeAdapter::serialize(&updateDataLen, &data, &serializedSize, sizeof(updateDataLen),
|
||||
SerializeIF::Endianness::BIG);
|
||||
std::memcpy(data, updateData, updateDataLen);
|
||||
if (updateDataLen % 2 != 0) {
|
||||
spParams.setPayloadLen(META_DATA_LENGTH + updateDataLen + 1);
|
||||
// The data field must be two bytes aligned. Thus, in case the number of bytes to write is odd
|
||||
@ -1122,6 +1121,13 @@ class WriteMemory : public ploc::SpTcBase {
|
||||
} else {
|
||||
spParams.setPayloadLen(META_DATA_LENGTH + updateDataLen);
|
||||
}
|
||||
// To avoid crashes in this unexpected case
|
||||
ReturnValue_t result = checkPayloadLen();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(data, updateData, updateDataLen);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user