system/cle: overlong line executed as a truncated command at EOL
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- cli, embedded-iot
Research direction
Read system/cle/cle.c: start at struct cle_s and the cle() loop that inserts printable/tab characters, then find where \n is handled and the line is returned to NSH. Add a bool overflow flag that is set when insertion no longer fits (emit BEL, keep consuming), and on newline while overflowing clear the buffer, echo \r\n and return OK. Verify by building sim:nsh with CONFIG_NSH_CLE=y and CONFIG_LINE_MAX=80 and feeding an overlong poweroff line followed by uname -a; done means the overlong line is discarded, the follow-up runs, and an exactly-fitting line still executes.
Written by the indexing model from the issue text.
Description
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, not a board); Linux x86_64, gcc 11.4; CONFIG_NSH_CLE=y, CONFIG_SYSTEM_CLE=y, CONFIG_LINE_MAX=80 (79 usable bytes).
Repro
- Build
sim:nshwith the configuration above. - Write
powerofffollowed by 200Aand\nto stdin. - 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) — insertion stops at 79 bytes and further bytes ring the bell, but the newline still submits the truncated buffer:
nsh> poweroff AAAA... <- 79 bytes accepted, further bytes rejected with BEL
(process exits with status 0 within 0.5 s; the follow-up command never runs)
The tail of the line is not discarded: it is consumed as new input and runs as further commands (e.g. a run of C characters ends up executed as a command named C).
Expected — the whole line is discarded through EOL and the next command runs:
nsh> poweroff AAAA...<BEL> <- discarded; poweroff is not executed
(empty line returned to NSH)
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 bool overflow to struct cle_s. When a printable or tab character no longer fits, set overflow, emit BEL, and keep consuming bytes without inserting them. On \n while overflowing, clear the buffer, echo \r\n, and return OK so NSH receives an empty line. A line that exactly fits must still execute, and a failed newline insertion alone must not set overflow. The patch changes only system/cle/cle.c.
Patch: 0002-cle-discard-overlong-line.patch, posted in the first comment. It applies to master 7196658dffde (git apply --check returns 0). CLE only covers the interactive editor; NSH script mode still calls readline_fd(), so a product using CLE needs both patches.
Reported from an audit of NSH input handling. Patch is in the first comment; happy to rework it if maintainers prefer a different approach.
- Dominant language
- C
- Stars
- 474
- Forks
- 807
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 181
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/nuttx-apps
-
[FEATURE] Shrink getprime runs for OSTestPossibly taken @linguini1 claimed this 42 days ago. OpenType: Enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
apache/nuttx-apps#3620 · 6 comments · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
apache/nuttx-apps#4107 · 3 comments ·
Maintainers usually reply within 1 day
-
[TODO] move graphics/input -> input.May be free again @cederom claimed this 241 days ago, and no pull request is open. Open
apache/nuttx-apps#3436 · 1 assignee ·
Maintainers usually reply within 1 day
-
Type: Enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
apache/nuttx-apps#3258 · 1 comment · 2 reactions ·
Maintainers usually reply within 1 day
-
Community: Question
Difficulty 4/5 3-5 days Newbie friendliness 20/100
apache/nuttx-apps#3134 ·
Maintainers usually reply within 1 day
All issues in apache/nuttx-apps
Similar issues
-
Arch: ARM/AArch64 Doc
Difficulty 1/5 Under an hour Newbie friendliness 90/100
RT-Thread/rt-thread#12082 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
trezor/trezor-firmware#8357 ·
Maintainers usually reply within 2 days
-
ivorysql_ora: DBMS_SESSION lacks SLEEP (documented, not covered by #2763)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
good first issue kernel
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
JackFurton/who-would-build-a-kernel-in-java#316 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
PE5PVB/TEF6686_ESP32#970 ·