summaryrefslogtreecommitdiff
path: root/system/ruby/libedit-compat.patch
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-09-09 06:18:14 +0000
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-09-09 06:18:14 +0000
commitee8cd5c2f53b73410e492dd299f8b946b07e1806 (patch)
tree396d89bafd412b5e33982912cb3cb30a3111aa3a /system/ruby/libedit-compat.patch
parent4a3fb555bd3f8141225a2b5e40f2a5fd7d9484ec (diff)
downloadpackages-ee8cd5c2f53b73410e492dd299f8b946b07e1806.tar.gz
packages-ee8cd5c2f53b73410e492dd299f8b946b07e1806.tar.bz2
packages-ee8cd5c2f53b73410e492dd299f8b946b07e1806.tar.xz
packages-ee8cd5c2f53b73410e492dd299f8b946b07e1806.zip
system/ruby: libedit compatibility patch [read:]
Ruby pretends editline (libedit) is readline. This is normally fine. However, editline's readline emulation does not account for changes to rl_instream or rl_outstream. If a Ruby application using the Readline extension changes .input or .output, this will cause a use-after-free: ==32694== Invalid read of size 4 ==32694== at 0x4070A38: fwrite (fwrite.c:32) ==32694== by 0x406F707: fputs (fputs.c:7) ==32694== by 0x660EAC7: el_wgets (in /usr/lib/libedit.so.0.0.60) ==32694== by 0x6607BDB: el_gets (in /usr/lib/libedit.so.0.0.60) ==32694== by 0x6620EDB: readline (in /usr/lib/libedit.so.0.0.60) ==32694== by 0x65DE3D3: readline_get (readline.c:346) ==32694== by 0x4DFA49B: rb_protect (eval.c:996) ==32694== by 0x65DE4FF: readline_readline (readline.c:507) ==32694== by 0x4F7AD4B: call_cfunc_m1 (vm_insnhelper.c:1723) ==32694== Address 0x67503dc is 140 bytes inside a block of size 1,264 free'd ==32694== at 0x490AFC0: free (in /usr/lib/valgrind/vgpreload_memcheck-ppc64be-linux.so) ==32694== by 0x406D44F: fclose (fclose.c:35) ==32694== by 0x65DE013: clear_rl_outstream (readline.c:365) ==32694== by 0x65DE0DF: readline_s_set_output (readline.c:599) ==32694== Block was alloc'd at ==32694== at 0x49092C0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-ppc64be-linux.so) ==32694== by 0x406BEC7: fdopen (__fdopen.c:21) ==32694== by 0x65DE103: readline_s_set_output (readline.c:603) Since rl_instream and rl_outstream are read on each rl_initialize, and editline's rl_initialize is smart enough to not leak memory if it is called multiple times during program execution, we use this as a way to force re-reading of rl_instream and rl_outstream. I hate this patch; I really do. Better fixes are highly welcome.
Diffstat (limited to 'system/ruby/libedit-compat.patch')
-rw-r--r--system/ruby/libedit-compat.patch22
1 files changed, 22 insertions, 0 deletions
diff --git a/system/ruby/libedit-compat.patch b/system/ruby/libedit-compat.patch
new file mode 100644
index 000000000..601a9feea
--- /dev/null
+++ b/system/ruby/libedit-compat.patch
@@ -0,0 +1,22 @@
+--- ruby-2.5.5/ext/readline/readline.c.old 2017-09-30 08:35:23.000000000 +0000
++++ ruby-2.5.5/ext/readline/readline.c 2019-09-09 06:12:00.300098741 +0000
+@@ -571,6 +571,9 @@
+ rb_syserr_fail(save_errno, "fdopen");
+ }
+ rl_instream = readline_rl_instream = f;
++#ifdef HAVE_EDITLINE_READLINE_H
++ rl_initialize();
++#endif
+ readline_instream = input;
+ }
+ return input;
+@@ -607,6 +610,9 @@
+ rb_syserr_fail(save_errno, "fdopen");
+ }
+ rl_outstream = readline_rl_outstream = f;
++#ifdef HAVE_EDITLINE_READLINE_H
++ rl_initialize();
++#endif
+ readline_outstream = output;
+ }
+ return output;