Skip to content

Commit

Permalink
Merge pull request #148 from i-jaffer/master
Browse files Browse the repository at this point in the history
[fix][log]修复log index2addr 计算溢出风险以及优化 ef_log_read 函数参数错误判断处理 #146 #147
  • Loading branch information
armink authored Dec 10, 2022
2 parents 91eb583 + a5f0947 commit aaa1681
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions easyflash/src/ef_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ static uint32_t log_index2addr(size_t index) {
if (log_start_addr + index + header_total_offset < log_area_start_addr + LOG_AREA_SIZE) {
return log_start_addr + index + header_total_offset;
} else {
return log_start_addr + index + header_total_offset - LOG_AREA_SIZE;

return (log_start_addr + index + header_total_offset) % LOG_AREA_SIZE;
}
}
}
Expand All @@ -490,8 +489,14 @@ EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size) {
return result;
}

EF_ASSERT(size % 4 == 0);
EF_ASSERT(index < cur_using_size);
if (size % 4 == 0) {
EF_DEBUG("Error: size must be word aligned.");
return EF_READ_ERR;
}
if (index < cur_using_size) {
EF_DEBUG("Error: index out of ranges, current using size is %d", cur_using_size);
return EF_READ_ERR;
}

if (index + size > cur_using_size) {
EF_DEBUG("Warning: Log read size out of bound. Cut read size.\n");
Expand Down

0 comments on commit aaa1681

Please sign in to comment.