UB/crashes with libedit
还没有人认领这个 Issue。
评估
调研方向
从 readline_s_set_output() 和 clear_rl_outstream() 开始,然后跟踪 rl_initialize() 如何在 libedit 中存储 rl_outstream。使用 libedit 和 musl libc 重现崩溃,并调查报告中提到的相关 rl_instream 路径。当 readline 输出不再访问已关闭的 FILE*,且报告中的崩溃得到阻止时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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 inel->el_outfile.
from that point on, libedit only operates on el_outfile in itsEditLine*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).
- 主要语言
- C
- 星标
- 14
- 派生
- 7
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/readline-ext 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 42/100
ruby/readline-ext#20 ·
-
难度 1/5 1 小时以内 新手友好度 35/100
ruby/readline-ext#17 ·
查看 ruby/readline-ext 的全部 Issue
相似的 Issue
-
task
难度 2/5 1-3 小时 新手友好度 70/100
vsanthanam/JBird#429 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
bug documentation
难度 2/5 1-3 小时 新手友好度 75/100
es-ude/OnDeviceTraining#459 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
bilelmoussaoui/gobject-linter#199 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
bradcypert/plum#53 ·