Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

UB/crashes with libedit

Đang mở
#31 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
c, ruby
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu từ readline_s_set_output() và clear_rl_outstream(), sau đó lần theo cách rl_initialize() lưu rl_outstream trong libedit. Tái hiện sự cố crash với libedit và musl libc, đồng thời điều tra đường dẫn rl_instream liên quan được đề cập trong báo cáo. Hoàn thành khi đầu ra của readline không còn truy cập vào một FILE* đã đóng và sự cố crash được báo cáo được ngăn chặn.

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

Mô tả

the code mentions compatibility with libedit, however the following happens in practice (e.g. while using irb from ruby 2.5.0):

  • libedit initializes internal copy of rl_outstream FILE* pointer during rl_initialize()
    e = el_init_internal(rl_readline_name, rl_instream, rl_outstream, ...). this saves the current rl_outstream in el->el_outfile.
    from that point on, libedit only operates on el_outfile in its EditLine* context.
  • in this module, clear_rl_outstream() is called from readline_s_set_output() which fclose()s rl_outstream. then rl_outstream gets a fresh FILE* assigned - however this does not affect libedit which continues using its el_outfile struct member.
  • next attempt to write anything to the output file via readline API causes a segfault - at least with musl libc, which is stricter in regards to UB.

probably this was never caught because the developers used glibc where the fclose() FILE structure happened to stay in RAM at the same address. or maybe the new FILE was allocated at the exact same address. it's 100% reproducible using libedit (latest release) and musl libc, and likely when using address sanitizer even on glibc.

it's likely that rl_instream handling has the same bug, but i only investigated the crash i actually got.

arguably it's a bug of libedit to supply rl_outstream but then use it only for initialization - but it appears nobody else was closing the FILE behind libedit's back so far, else it would be fixed in latest libedit version.

(background: i was about to update ruby from 2.5.0 to a newer version in my distro sabotage linux and noticed irb crashing, so i wanted to fix it before switching to a more modern version, so someone who needs to use the old version for whatever reason can go back in commit history and produce a 100% working version).

Ngôn ngữ chính
C
Star
14
Fork
7
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

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 ruby/readline-ext

Tất cả issue của ruby/readline-ext

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.