Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

【优化】读写接口溢出问题 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/fal_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int fal_partition_read(const struct fal_partition *part, uint32_t addr, uint8_t
assert(part);
assert(buf);

if (addr + size > part->len)
if (addr >= part->len || part->len - addr < size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (addr >= part->len || part->len - addr < size)
if (addr >= part->len || addr + size > part->len)

改成这种方式吧,上面那个感觉逻辑不太直观

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他的意思是 addr+size 有可能会溢出吧,所以改成了减

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有测试的用例吗?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实只有当,fal 管理的地址空间达到 4G 的时候,才会出现这个问题。
021482fd51f8bee487cb0850fe3e4a1

{
log_e("Partition read error! Partition address out of bound.");
return -1;
Expand Down Expand Up @@ -452,7 +452,7 @@ int fal_partition_write(const struct fal_partition *part, uint32_t addr, const u
assert(part);
assert(buf);

if (addr + size > part->len)
if (addr >= part->len || part->len - addr < size)
{
log_e("Partition write error! Partition address out of bound.");
return -1;
Expand Down Expand Up @@ -491,7 +491,7 @@ int fal_partition_erase(const struct fal_partition *part, uint32_t addr, size_t

assert(part);

if (addr + size > part->len)
if (addr >= part->len || part->len - addr < size)
{
log_e("Partition erase error! Partition address out of bound.");
return -1;
Expand Down