Skip to content

[utest][klibc] Keep TC_rt_memmove_too_long inside its buffers - #12065

Open
parthitce wants to merge 1 commit into
RT-Thread:masterfrom
linumiz:rh850/fix-utest-memmove
Open

parthitce wants to merge 1 commit into
RT-Thread:masterfrom
linumiz:rh850/fix-utest-memmove

Conversation

@parthitce

Copy link
Copy Markdown
Contributor

TC_rt_memmove_too_long copies 11 bytes from a 6-byte source into a 10-byte buffer, so it reads and writes past both arrays. Use 11-byte buffers. The assertions are unchanged.

Test: RH850 qemu-rh850-u2c kernel_basic at -O2: the stack corruption crashed the run in rt_memmove before, 22/22 pass after.

@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 rh850/fix-utest-memmove
    Enter PR branch rh850/fix-utest-memmove in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 rh850/fix-utest-memmove 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the rh850/fix-utest-memmove branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added the Kernel PR has src relate code label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: kernel

Reviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837

Changed Files (Click to expand)
  • src/klibc/utest/TC_rt_memmove.c

📊 Current Review Status (Last Updated: 2026-11-19 04:13 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复核 / Review

复核 184ba862:src/dest 扩到 11 字节后,原来的越界读写已消除,改动本身正确。CI 全绿。

非阻塞 / Non-blocking — 该用例不再能发现“拷贝长度超过 NUL”的回归。
TC_rt_memmove.c:74-80 中 src[11] = "Short" 的 5..10 字节全部为 0,dest[11] = {0} 也全为 0;即使 rt_memmove() 错误地只拷贝到 NUL 为止,两条断言仍会通过,用例名 too_long 实际不再覆盖 n > strlen 的语义。

建议(二选一):

  1. 保留回归意图:把 src 尾部填非零值(例如 {'S','h','o','r','t',0,'X','Y','Z','W','V'}),dest 预填 0xAA,再断言 5..10 字节与 src 一致;
  2. 若只想验证零填充拷贝,则改名为 TC_rt_memmove_zero_padding 或删除该用例。

The assertions can no longer distinguish a memmove that stops at NUL, since both the source tail and destination are zeroed. Either use a non-zero tail with a 0xAA-filled destination, or rename/remove the case.

The test copied 11 bytes from a 6-byte source into a 10-byte buffer. It
corrupted the stack at -O2 on RH850. Copy 11 bytes between 11-byte
buffers.

Also check the bytes past the NUL, so a copy that stops early fails.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
@parthitce
parthitce force-pushed the rh850/fix-utest-memmove branch from 184ba86 to 918d202 Compare November 18, 2026 20:13
@parthitce

Copy link
Copy Markdown
Contributor Author

复核 / Review

复核 184ba862:src/dest 扩到 11 字节后,原来的越界读写已消除,改动本身正确。CI 全绿。

非阻塞 / Non-blocking — 该用例不再能发现“拷贝长度超过 NUL”的回归。 TC_rt_memmove.c:74-80 中 src[11] = "Short" 的 5..10 字节全部为 0,dest[11] = {0} 也全为 0;即使 rt_memmove() 错误地只拷贝到 NUL 为止,两条断言仍会通过,用例名 too_long 实际不再覆盖 n > strlen 的语义。

建议(二选一):

1. 保留回归意图:把 `src` 尾部填非零值(例如 `{'S','h','o','r','t',0,'X','Y','Z','W','V'}`),`dest` 预填 `0xAA`,再断言 5..10 字节与 `src` 一致;

2. 若只想验证零填充拷贝,则改名为 `TC_rt_memmove_zero_padding` 或删除该用例。

The assertions can no longer distinguish a memmove that stops at NUL, since both the source tail and destination are zeroed. Either use a non-zero tail with a 0xAA-filled destination, or rename/remove the case.

Thanks for the review @BernardXiong, went with option 1. src now has a non-zero tail, dest is filled with 0xAA, and all 11 bytes are compared, so a copy that stops at NUL fails now.

Kindly revisit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kernel PR has src relate code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants