Skip to content

[finsh][shell] Print FinSH prompt with a fixed format string#11307

Open
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-format-string-injection
Open

[finsh][shell] Print FinSH prompt with a fixed format string#11307
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-format-string-injection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

The FinSH/MSH prompt path treated the prompt buffer as a rt_kprintf() format string. When the working directory contained format specifiers, the prompt could leak stack data or crash instead of printing the path literally.

  • Problem

    • finsh_get_prompt() builds the prompt from static text plus the current working directory.
    • components/finsh/shell.c then printed that buffer directly with rt_kprintf(FINSH_PROMPT), making directory names part of the format string.
  • Change

    • Update both direct prompt-printing call sites in components/finsh/shell.c to use a fixed format string.
    • Keep prompt construction and shell behavior unchanged; only the sink is hardened.
  • Effect

    • Working directory names are printed verbatim in the prompt.
    • Format specifiers in directory names are no longer interpreted by rt_kprintf().
/* before */
rt_kprintf(FINSH_PROMPT);

/* after */
rt_kprintf("%s", FINSH_PROMPT);

Copilot AI and others added 3 commits April 1, 2026 13:52
Agent-Logs-Url: https://github.com/RT-Thread/rt-thread/sessions/b514540d-90fa-4ac9-bb74-5c84dd939b40

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/RT-Thread/rt-thread/sessions/b514540d-90fa-4ac9-bb74-5c84dd939b40

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/RT-Thread/rt-thread/sessions/b514540d-90fa-4ac9-bb74-5c84dd939b40

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix format-string injection in FinSH prompt [finsh][shell] Print FinSH prompt with a fixed format string Apr 1, 2026
Copilot AI requested a review from BernardXiong April 1, 2026 13:59
@BernardXiong BernardXiong marked this pull request as ready for review April 4, 2026 07:44
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 4, 2026

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/finsh/shell.c

📊 Current Review Status (Last Updated: 2026-04-04 15:44 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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Format-string injection in FinSH prompt via directory name

2 participants