1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

Merged in LP-625_Fix_unsafe_use_of_temporary_data (pull request #548)

LP-625 Fix for unsafe use of temporary data

Approved-by: Eric Price
This commit is contained in:
Vladimir Zidar 2022-06-14 20:08:34 +00:00 committed by Eric Price
commit cfaf2df79d

View File

@ -229,15 +229,16 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
// cycle until there is space for another object
while (start + header_len + 1 < data_len) {
memset(&fields, 0xFF, total_len);
uint8_t *tmp = logEntry->getData().Data; // avoid compiler warning regarding addressing a temporary make sure tmp lives until after memcpy
memcpy(&fields, &tmp[start], header_len);
ExtendedDebugLogEntry::DataFields tmp = logEntry->getData();
memcpy(&fields, &tmp.Data[start], header_len);
// check wether a packed object is found
// note that empty data blocks are set as 0xFF in flight side to minimize flash wearing
// thus as soon as this read outside of used area, the test will fail as lenght would be 0xFFFF
quint32 toread = header_len + fields.Size;
if (!(toread + start > data_len)) {
uint8_t *tmp = logEntry->getData().Data; // avoid compiler warning regarding addressing a temporary make sure tmp lives until after memcpy
memcpy(&fields, &tmp[start], toread);
tmp = logEntry->getData();
memcpy(&fields, &tmp.Data[start], toread);
ExtendedDebugLogEntry *subEntry = new ExtendedDebugLogEntry();
subEntry->setData(fields, m_objectManager);
m_logEntries << subEntry;