xhh233 opened a new issue, #4108:
URL: https://github.com/apache/nuttx-apps/issues/4108

   # system/cle: overlong line executed as a truncated command at EOL
   
   **Repository:** `apache/nuttx-apps` · **Component:** `system/cle/cle.c` 
(selected by `CONFIG_NSH_CLE=y`)
   
   **Environment:** NuttX Apps 13.1.0, also master `7196658dffde`; host 
`sim:nsh` (not QEMU/board); Linux x86_64, gcc 11.4; `CONFIG_NSH_CLE=y`, 
`CONFIG_SYSTEM_CLE=y`, `CONFIG_LINE_MAX=80` (79 usable bytes).
   
   **Repro (3 steps)**
   1. Build `sim:nsh` with the config above.
   2. Write `poweroff ` + 200 × `A` + `\n` to stdin.
   3. After 0.5 s write `uname -a\n`; check whether it runs.
   
   **Actual (stock 13.1.0)** — insert fails at 79 bytes, but EOL submits the 
truncated buffer:
   ```
   # case=overlong_poweroff CONFIG_NSH_CLE=y CONFIG_LINE_MAX=80
   # rc=0 alive_at_timeout=False stdout_bytes=17967 prompts=1
   nsh> poweroff AAAA... (79 B; further bytes BEL)
   nsh> echo CCC... (75×C)
   CCCC... (74-byte prefix executed)
   ```
   
   **Expected** — discard the whole line through EOL, keep the next command:
   ```
   # rc=-9 alive_at_timeout=True prompts=3
   nsh> poweroff AAAA...<BEL>...
   (empty line; poweroff not executed)
   nsh> uname -a
   NuttX 0.0.0 0 ... sim sim
   ```
   
   **Fix suggestion:** add `bool overflow` to `struct cle_s`. When a 
printable/tab character no longer fits, set `overflow`, BEL, and consume 
further bytes without inserting. On `\n` while overflowing, clear the buffer, 
echo `\r\n`, and return `OK` so NSH gets an empty line. A line that exactly 
fits must still execute; a failed newline insert alone must not set `overflow`. 
Patch changes only `system/cle/cle.c`.
   
   **Patch:** `0002-cle-discard-overlong-line.patch` (posted in the first 
comment; applies to master `7196658dffde`, `git apply --check` rc=0). CLE 
covers the interactive editor only; script mode still uses `readline_fd()`, so 
a CLE product needs both patches.
   
   ---
   Report from an independent audit; patch is in the first comment. Companion 
issue for `system/readline` covers the same consequence in the other NSH 
frontend.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to