Fix memory overridden (#209)
* fix: memory was written out of its boundary. Co-authored-by: 朱天龙 (Armink) <armink.ztl@gmail.com> Co-authored-by: shihang.zhang <shihang.zhang.ext@siemens.com>
This commit is contained in:
parent
519a06f65a
commit
39e81fa9b2
|
@ -337,4 +337,3 @@ typedef struct fdb_blob *fdb_blob_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _FDB_DEF_H_ */
|
#endif /* _FDB_DEF_H_ */
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@ static fdb_err_t read_kv(fdb_kvdb_t db, fdb_kv_t kv)
|
||||||
fdb_err_t result = FDB_NO_ERR;
|
fdb_err_t result = FDB_NO_ERR;
|
||||||
size_t len, size;
|
size_t len, size;
|
||||||
/* read KV header raw data */
|
/* read KV header raw data */
|
||||||
_fdb_flash_read((fdb_db_t)db, kv->addr.start, (uint32_t *)&kv_hdr, KV_HDR_DATA_SIZE);
|
_fdb_flash_read((fdb_db_t)db, kv->addr.start, (uint32_t *)&kv_hdr, sizeof(struct kv_hdr_data));
|
||||||
kv->status = (fdb_kv_status_t) _fdb_get_status(kv_hdr.status_table, FDB_KV_STATUS_NUM);
|
kv->status = (fdb_kv_status_t) _fdb_get_status(kv_hdr.status_table, FDB_KV_STATUS_NUM);
|
||||||
kv->len = kv_hdr.len;
|
kv->len = kv_hdr.len;
|
||||||
|
|
||||||
|
@ -382,7 +382,7 @@ static fdb_err_t read_sector_info(fdb_kvdb_t db, uint32_t addr, kv_sec_info_t se
|
||||||
FDB_ASSERT(sector);
|
FDB_ASSERT(sector);
|
||||||
|
|
||||||
/* read sector header raw data */
|
/* read sector header raw data */
|
||||||
_fdb_flash_read((fdb_db_t)db, addr, (uint32_t *)&sec_hdr, SECTOR_HDR_DATA_SIZE);
|
_fdb_flash_read((fdb_db_t)db, addr, (uint32_t *)&sec_hdr, sizeof(struct sector_hdr_data));
|
||||||
|
|
||||||
sector->addr = addr;
|
sector->addr = addr;
|
||||||
sector->magic = sec_hdr.magic;
|
sector->magic = sec_hdr.magic;
|
||||||
|
@ -725,7 +725,7 @@ static fdb_err_t format_sector(fdb_kvdb_t db, uint32_t addr, uint32_t combined_v
|
||||||
result = _fdb_flash_erase((fdb_db_t)db, addr, db_sec_size(db));
|
result = _fdb_flash_erase((fdb_db_t)db, addr, db_sec_size(db));
|
||||||
if (result == FDB_NO_ERR) {
|
if (result == FDB_NO_ERR) {
|
||||||
/* initialize the header data */
|
/* initialize the header data */
|
||||||
memset(&sec_hdr, FDB_BYTE_ERASED, SECTOR_HDR_DATA_SIZE);
|
memset(&sec_hdr, FDB_BYTE_ERASED, sizeof(struct sector_hdr_data));
|
||||||
_fdb_set_status(sec_hdr.status_table.store, FDB_SECTOR_STORE_STATUS_NUM, FDB_SECTOR_STORE_EMPTY);
|
_fdb_set_status(sec_hdr.status_table.store, FDB_SECTOR_STORE_STATUS_NUM, FDB_SECTOR_STORE_EMPTY);
|
||||||
_fdb_set_status(sec_hdr.status_table.dirty, FDB_SECTOR_DIRTY_STATUS_NUM, FDB_SECTOR_DIRTY_FALSE);
|
_fdb_set_status(sec_hdr.status_table.dirty, FDB_SECTOR_DIRTY_STATUS_NUM, FDB_SECTOR_DIRTY_FALSE);
|
||||||
sec_hdr.magic = SECTOR_MAGIC_WORD;
|
sec_hdr.magic = SECTOR_MAGIC_WORD;
|
||||||
|
@ -1098,7 +1098,7 @@ static fdb_err_t create_kv_blob(fdb_kvdb_t db, kv_sec_info_t sector, const char
|
||||||
return FDB_KV_NAME_ERR;
|
return FDB_KV_NAME_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&kv_hdr, FDB_BYTE_ERASED, KV_HDR_DATA_SIZE);
|
memset(&kv_hdr, FDB_BYTE_ERASED, sizeof(struct kv_hdr_data));
|
||||||
kv_hdr.magic = KV_MAGIC_WORD;
|
kv_hdr.magic = KV_MAGIC_WORD;
|
||||||
kv_hdr.name_len = strlen(key);
|
kv_hdr.name_len = strlen(key);
|
||||||
kv_hdr.value_len = len;
|
kv_hdr.value_len = len;
|
||||||
|
@ -1751,4 +1751,3 @@ bool fdb_kv_iterate(fdb_kvdb_t db, fdb_kv_iterator_t itr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(FDB_USING_KVDB) */
|
#endif /* defined(FDB_USING_KVDB) */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue