Skip to content

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

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

[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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