From 2e2afcd6c50375073cb0257fc56fb30de7125cac Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 20 Aug 2022 01:45:49 +0200 Subject: [PATCH] moved a size check --- .../PlocSupervisorDefinitions.h | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index d6f74909..8f4e2154 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -1121,19 +1121,8 @@ class WriteMemory : public ploc::SpTcBase { uint8_t* updateData) { size_t serializedSize = 0; uint8_t* data = payloadStart; - SerializeAdapter::serialize(&memoryId, &data, &serializedSize, sizeof(memoryId), - SerializeIF::Endianness::BIG); - SerializeAdapter::serialize(&n, &data, &serializedSize, sizeof(n), - SerializeIF::Endianness::BIG); - SerializeAdapter::serialize(&startAddr, &data, &serializedSize, sizeof(startAddr), - SerializeIF::Endianness::BIG); - SerializeAdapter::serialize(&updateDataLen, &data, &serializedSize, sizeof(updateDataLen), - SerializeIF::Endianness::BIG); 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 - // a value of zero is added here - *(data + updateDataLen + 1) = 0; } else { spParams.setPayloadLen(META_DATA_LENGTH + updateDataLen); } @@ -1142,7 +1131,20 @@ class WriteMemory : public ploc::SpTcBase { if (result != HasReturnvaluesIF::RETURN_OK) { return result; } + SerializeAdapter::serialize(&memoryId, &data, &serializedSize, sizeof(memoryId), + SerializeIF::Endianness::BIG); + SerializeAdapter::serialize(&n, &data, &serializedSize, sizeof(n), + SerializeIF::Endianness::BIG); + SerializeAdapter::serialize(&startAddr, &data, &serializedSize, sizeof(startAddr), + SerializeIF::Endianness::BIG); + SerializeAdapter::serialize(&updateDataLen, &data, &serializedSize, sizeof(updateDataLen), + SerializeIF::Endianness::BIG); std::memcpy(data, updateData, updateDataLen); + if (updateDataLen % 2 != 0) { + // The data field must be two bytes aligned. Thus, in case the number of bytes to write is odd + // a value of zero is added here + data[updateDataLen + 1] = 0; + } return HasReturnvaluesIF::RETURN_OK; } };