fix(finsh): Fix crash in 'tail' command with insufficient '-n' arguments#10977
fix(finsh): Fix crash in 'tail' command with insufficient '-n' arguments#10977Rbb666 merged 1 commit intoRT-Thread:masterfrom
Conversation
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-11-25 13:21 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
我要晚点测测 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash bug in the MSH shell's tail command that occurs when users incorrectly provide the -n parameter without sufficient arguments. The fix adds proper argument validation to prevent accessing out-of-bounds memory (argv[3]) when the required parameters are missing.
Key Changes:
- Adds argument count validation before accessing argv[3] to prevent crash
- Enhances error messages and usage information for better user guidance
- Adds comprehensive Doxygen documentation for the cmd_tail function
Comments suppressed due to low confidence (1)
components/finsh/msh_file.c:813
- English: Missing space after
ifkeyword. RT-Thread coding style requires a space between control keywords and parentheses (e.g.,if (condition)notif(condition)). While this line is not part of the diff, I notice this pattern exists in the surrounding context. Please ensure consistent formatting.
中文: if 关键字后缺少空格。RT-Thread 编码风格要求控制关键字和括号之间有空格(例如 if (condition) 而不是 if(condition))。虽然这一行不是 diff 的一部分,但我注意到周围上下文中存在这种模式。请确保格式一致。
Note: This is existing code, not introduced by this PR.
if(total_lines == 0)
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
执行 tail -n 或 tail -n 这种缺少必要参数的命令。
tail -n flash_sys.log 命令将 flash_sys.log 误解析为行数,然后尝试访问不存在的 argv[3] 来获取文件名,这导致了异常。
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up