Skip to content

Commit ece756c

Browse files
LDong-ArmSeppo Takalo
andcommitted
TDBStore: pad record header to whole program size before storing it
Previously, when writing a record header into a TDBStore, we took the pointer to the record_header_t variable as the input, but used a program-aligned chunk size which is larger. As a result, garbage from the stack memory gets written. This commit fixes that by buffering the record header. Co-authored-by: Seppo Takalo <[email protected]>
1 parent 4e0d07d commit ece756c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

storage/kvstore/source/TDBStore.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,10 @@ int TDBStore::copy_record(uint8_t from_area, uint32_t from_offset, uint32_t to_o
847847
}
848848

849849
chunk_size = align_up(sizeof(record_header_t), _prog_size);
850-
ret = write_area(1 - from_area, to_offset, chunk_size, &header);
850+
// The record header takes up whole program units
851+
memset(_work_buf, 0, chunk_size);
852+
memcpy(_work_buf, &header, sizeof(record_header_t));
853+
ret = write_area(1 - from_area, to_offset, chunk_size, _work_buf);
851854
if (ret) {
852855
return ret;
853856
}

0 commit comments

Comments
 (0)