system/cle: overlong line executed as a truncated command at EOL

Abierto Apto para principiantes
#4,108 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
cli, embedded-iot

Línea de trabajo

Lee system/cle/cle.c: empieza en struct cle_s y en el bucle cle() que inserta caracteres imprimibles y tabulaciones, luego encuentra dónde se gestiona \n y se devuelve la línea a NSH. Añade un indicador bool overflow que se activa cuando la inserción ya no cabe (emite BEL y sigue consumiendo). Al recibir un salto de línea mientras hay desbordamiento, vacía el búfer, haz eco de \r\n y devuelve OK. Para verificarlo, compila sim:nsh con CONFIG_NSH_CLE=y y CONFIG_LINE_MAX=80 y envía una línea demasiado larga poweroff seguida de uname -a; está terminado cuando la línea demasiado larga se descarta, el comando siguiente se ejecuta y una línea que cabe exactamente sigue ejecutándose.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

  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) — 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.

Lenguaje dominante
C
Estrellas
474
Forks
807
Merge medio
1 d 11 h
PR fusionados (30 d)
181

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/nuttx-apps

Todos los issues de apache/nuttx-apps

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.