drivers: fix CFI MTD array bounds checks#11558
Conversation
Generated-by: OpenAI Codex Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-07-05 22:02 CST)
📝 Review Instructions
|
Summary
erase_region_info.sect_count == RT_ARRAY_SIZE(fdev->sect)as full before writingfdev->sect[sect_count]andfdev->protect[sect_count].Details
query->num_erase_regionscomes from the CFI query data, but the localerase_region_infoarray can be configured withCFI_QUERY_ERASE_REGIONS_MAX. Clamping it once after the query is read keeps the later fixup/reverse helpers and the main erase-region loop on the same bounded value.The sector table check currently allows
sect_count == RT_ARRAY_SIZE(fdev->sect), then writes through that index. This changes the guard to>=so the arrays are treated as full before the out-of-bounds write.Testing
git diff --check HEAD~1..HEADcomponents/drivers/mtd/mtd-cfi.cbounds paths around CFI fixup/reverse and sector table population.Not run: full
sconsbuild, because this local Windows environment does not have the RT-Threadscons/pkgsbuild tools installed.