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

   # system/readline: overlong NSH line runs as a truncated prefix
   
   **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/board); Linux x86_64, gcc 11.4; `CONFIG_NSH_READLINE=y`, 
`CONFIG_READLINE_EDIT=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)** — 79 bytes are submitted when the buffer fills; 
`poweroff` runs before EOL:
   ```
   nsh> poweroff AAAA... (79-byte prefix submitted at buffer full)
   # rc=0 alive_at_timeout=False prompts=1 nuttx_banner=0
   nsh> echo CCC... (75×C)
   nsh> C
   nsh: C: command not found
   ```
   
   **Expected** — discard the whole line through EOL, keep the next command:
   ```
   nsh> poweroff AAAA...<BEL>... (discarded; poweroff not executed)
   nsh> uname -a
   NuttX ... sim sim
   # rc=-9 alive_at_timeout=True prompts=3
   ```
   
   **Fix suggestion:** add an `overflow` state in `readline_common()`. When a 
character plus the NUL no longer fits, 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`) must still execute. Patch changes only 
`system/readline/readline_common.c`.
   
   **Patch:** `0001-readline-discard-overlong-line.patch` (posted in the first 
comment; applies to master `7196658dffde`, `git apply --check` rc=0). Companion 
CLE issue covers the same consequence in `system/cle/cle.c`.
   
   
   ---
   
   Report from an independent audit; patch is in the first comment. Happy to 
adjust the approach if maintainers prefer a different fix.
   


-- 
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