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

Đang mở Phù hợp với người mới
#4,108 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c
Lĩnh vực
cli, embedded-iot

Hướng nghiên cứu

Đọc system/cle/cle.c: bắt đầu từ struct cle_s và vòng lặp cle() chèn các ký tự in được và tab, sau đó tìm nơi \n được xử lý và dòng được trả về cho NSH. Thêm cờ bool overflow được đặt khi việc chèn không còn vừa nữa (phát BEL, tiếp tục đọc). Khi gặp ký tự xuống dòng trong lúc tràn, xóa bộ đệm, phản hồi \r\n và trả về OK. Để kiểm tra, biên dịch sim:nsh với CONFIG_NSH_CLE=y và CONFIG_LINE_MAX=80, rồi nhập một dòng quá dài poweroff tiếp theo là uname -a; hoàn thành khi dòng quá dài bị loại bỏ, lệnh tiếp theo được chạy và dòng vừa khít vẫn được thực thi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C
Star
474
Fork
807
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
181

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/nuttx-apps

Tất cả issue của apache/nuttx-apps

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.