Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

UB/crashes with libedit

Aperta
#31 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
c, ruby
Ambito
cli

Direzione di ricerca

Inizia da readline_s_set_output() e clear_rl_outstream(), quindi segui il modo in cui rl_initialize() memorizza rl_outstream in libedit. Riproduci il crash con libedit e musl libc e analizza il percorso correlato di rl_instream menzionato nel report. Il lavoro è completato quando l’output di readline non accede più a un FILE* chiuso e il crash segnalato viene impedito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C
Stelle
14
Fork
7
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/readline-ext

Tutte le issue di ruby/readline-ext

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.