system/readline: overlong NSH line runs as a truncated prefix

未关闭
#4,107 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c

调研方向

Read system/readline/readline_common.c, especially the readline_common() character loop where a received byte plus the terminating NUL fills CONFIG_LINE_MAX. Reproduce on sim:nsh by feeding poweroff plus 200 As and a newline; confirm the 79-byte prefix is submitted. Done means an overlong line emits BEL, discards through newline/CR and EOF, resets the buffer, returns 0, while a line of exactly LINE_MAX - 1 bytes still runs. The patch in the first comment is a reference, not something a newcomer should duplicate.

由索引模型根据 Issue 内容生成。

描述

Repository: apache/nuttx-apps · Component: system/readline/readline_common.c (used by NSH)

Environment: NuttX Apps 13.1.0, also master 7196658dffde; host sim:nsh (not QEMU, not a board); Linux x86_64, gcc 11.4; CONFIG_NSH_READLINE=y, CONFIG_READLINE_EDIT=y, CONFIG_LINE_MAX=80 (79 usable bytes).

Repro

  1. Build sim:nsh with the configuration above.
  2. Write poweroff followed by 200 A and \n to stdin.
  3. After 0.5 s write uname -a\n, then observe whether the process is still alive and whether the follow-up command runs. The test driver kills the process after a 2 s timeout if it did not exit on its own.

Actual (stock 13.1.0) — when the buffer fills, the 79-byte prefix is submitted as a command, so poweroff runs before the newline is ever seen:

nsh> poweroff AAAA...        <- 79-byte prefix submitted at buffer full
(process exits with status 0 within 0.5 s; the follow-up command never runs)

The remaining bytes are not discarded either: they are read as further input and parsed as additional commands, so the tail of a single long line also executes.

Expected — the whole line is discarded through EOL and the next command runs:

nsh> poweroff AAAA...<BEL>   <- discarded; poweroff is not executed
nsh> uname -a
NuttX ... sim sim            <- follow-up command runs normally
(process stays alive; the harness kills it after the 2 s timeout)

Fix suggestion: add an overflow state in readline_common(). When a character plus the NUL no longer fits, emit BEL and drop every byte until \n/\r; then clear the buffer and return 0. On EOF while overflowing, discard the partial line and return 0. A line that exactly fills the buffer (LINE_MAX - 1 bytes) must still execute. The patch changes only system/readline/readline_common.c.

Patch: 0001-readline-discard-overlong-line.patch, posted in the first comment. It applies to master 7196658dffde (git apply --check returns 0). A companion report covers the same consequence in the other NSH frontend, system/cle/cle.c.


Reported from an audit of NSH input handling. Patch is in the first comment; happy to rework it if maintainers prefer a different approach.

主要语言
C
星标
474
派生
807
平均合并
1 天 11 小时
30 天内合并 PR
181

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/nuttx-apps 的其他 Issue

查看 apache/nuttx-apps 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。