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

オープン
#4,107 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
181

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/nuttx-apps のほかの issue

apache/nuttx-apps の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。