Ruby Issue Tracking System: Issues
https://redmine.ruby-lang.org/
https://redmine.ruby-lang.org/favicon.ico?1711330511
2020-12-14T22:59:10Z
Ruby Issue Tracking System
Redmine
Ruby master - Bug #17394 (Closed): TCPServer is not thread safe on win32
https://redmine.ruby-lang.org/issues/17394
2020-12-14T22:59:10Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<p>Hello, it looks like win32 version of TCPServer is not thread safe. I've extracted the following code from project:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s2">"socket"</span>
<span class="nb">require</span> <span class="s2">"parallel"</span>
<span class="o">::</span><span class="no">Parallel</span><span class="p">.</span><span class="nf">each</span><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">2</span><span class="p">,</span> <span class="ss">:in_threads</span> <span class="o">=></span> <span class="mi">2</span><span class="p">)</span> <span class="k">do</span>
<span class="o">::</span><span class="no">TCPServer</span><span class="p">.</span><span class="nf">open</span> <span class="mi">0</span> <span class="k">do</span> <span class="o">|</span><span class="n">server</span><span class="o">|</span>
<span class="n">thread</span> <span class="o">=</span> <span class="o">::</span><span class="no">Thread</span><span class="p">.</span><span class="nf">new</span> <span class="p">{</span> <span class="n">server</span><span class="p">.</span><span class="nf">accept</span><span class="p">.</span><span class="nf">close</span> <span class="p">}</span>
<span class="o">::</span><span class="no">TCPSocket</span><span class="p">.</span><span class="nf">open</span> <span class="s2">"localhost"</span><span class="p">,</span> <span class="n">server</span><span class="p">.</span><span class="nf">addr</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="n">thread</span><span class="p">.</span><span class="nf">join</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>It returns:</p>
<pre><code>in `accept': Bad file descriptor - not a socket file descriptor (Errno::EBADF)
</code></pre>
<p>You can fix this code by using <code>:in_threads => 1</code>. This is unique windows issue: GNU/Linux, FreeBSD and OSX works perfect. I think something is wrong in <code>win32</code> folder of ruby source code.</p>
<p>Can you please assign this issue to the developer familiar with <code>win32</code> folder? Thank you.</p>
Ruby master - Bug #16473 (Rejected): New deprecated warning disallows keyword arguments bypassing
https://redmine.ruby-lang.org/issues/16473
2020-01-02T17:10:37Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<p>Hello. I see that ruby 2.7.0 prints unnecessary deprecated warning during arguments bypassing.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">kw</span><span class="p">(</span><span class="ss">a: </span><span class="mi">1</span><span class="p">)</span>
<span class="nb">puts</span> <span class="s2">"kw </span><span class="si">#{</span><span class="n">a</span><span class="si">}</span><span class="s2">"</span>
<span class="k">end</span>
<span class="k">def</span> <span class="nf">non_kw</span><span class="p">(</span><span class="n">a</span> <span class="o">=</span> <span class="p">{},</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
<span class="nb">puts</span> <span class="s2">"non kw </span><span class="si">#{</span><span class="n">a</span><span class="si">}</span><span class="s2">"</span>
<span class="n">kw</span> <span class="o">*</span><span class="n">args</span>
<span class="k">end</span>
<span class="n">non_kw</span><span class="p">({</span> <span class="ss">:a</span> <span class="o">=></span> <span class="mi">2</span> <span class="p">},</span> <span class="ss">:a</span> <span class="o">=></span> <span class="mi">2</span><span class="p">)</span>
<span class="n">non_kw</span><span class="p">({</span> <span class="ss">:a</span> <span class="o">=></span> <span class="mi">3</span> <span class="p">})</span>
<span class="n">non_kw</span>
</code></pre>
<p>The right output is:</p>
<pre><code>non kw {:a=>2}
kw 2
non kw {:a=>3}
kw 1
non kw {}
kw 1
</code></pre>
<p>Ruby 2.7.0 provides deprecated warning:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="ss">warning: </span><span class="no">Using</span> <span class="n">the</span> <span class="n">last</span> <span class="n">argument</span> <span class="n">as</span> <span class="n">keyword</span> <span class="n">parameters</span> <span class="n">is</span> <span class="n">deprecated</span><span class="p">;</span> <span class="n">maybe</span> <span class="o">**</span> <span class="n">should</span> <span class="n">be</span> <span class="n">added</span> <span class="n">to</span> <span class="n">the</span> <span class="n">call</span>
</code></pre>
<p><code>*args</code> is bypassing arguments without any conversion. It looks like ruby converts last hash to keywords and than converts it back to hash. I think it is a bug.</p>
Ruby master - Bug #16397 (Closed): Line coverage is broken for until and while after guard clause
https://redmine.ruby-lang.org/issues/16397
2019-12-03T21:43:22Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<p>Hello. I was working on <a href="https://github.com/andrew-aladev/ruby-zstds" class="external">ruby gem</a> and received a bug with <a href="https://github.com/colszowka/simplecov/issues/764" class="external">simplecov</a>. See the following <a href="https://codecov.io/gh/andrew-aladev/ruby-zstds/src/master/lib/zstds/stream/reader.rb#L56" class="external">coverage report</a> for stream reader. Simplecov uses line coverage report from ruby vm.</p>
<p>Today I've finally found a way to <a href="https://gist.github.com/andrew-aladev/baa5d3ebe7718853756f75a5074e90b5" class="external">extract this bug</a> from gem source. Please use ruby 2.6.5 to run <code>ruby test.rb</code>. The result will be <code>[1, nil, 1, nil, 0, nil, 1]</code>. The right result is <code>[1, nil, 1, nil, 1, nil, 1]</code>.</p>
<p>We can workaround this bug by adding <code>puts</code> after guard clause. Another workaround is to rewrite inline <code>until</code> using <code>loop do + break if</code>. But guard case is the key. It breaks vm or vm trace system.</p>
<p>I will continue to investigate vm system. The suspicious thing is the method of calculating line number <code>use pos-1 because PC points next instruction at the beginning of instruction</code> but I am not sure.</p>
Ruby master - Feature #15923 (Rejected): New independent string without memcpy
https://redmine.ruby-lang.org/issues/15923
2019-06-14T13:51:41Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<p>Hello. I've just tried to implement extension for ruby that will provide large binary strings.</p>
<p>I've inspected latest ruby source code and found 2 functions: <em>rb_str_new</em> and <em>rb_str_new_static</em> .</p>
<ul>
<li>
<em>rb_str_new</em> allocates new memory and uses <em>memcpy</em> to copy from source string to new memory.</li>
<li>
<em>rb_str_new_static</em> uses existing source string as it is, but adds <em>STR_NOFREE</em> flag.</li>
</ul>
<p>Is it possible to create independent string from source string without memcpy that will be freed automatically? Thank you.</p>
Ruby master - Bug #13401 (Third Party's Issue): OpenSSL::SSL::SSLSocket :hostname= accessor removed
https://redmine.ruby-lang.org/issues/13401
2017-04-04T23:49:22Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<p>Hello. I've found a small issue, but it is important for security.</p>
<p>Some websites will force you to use SNI. For example "httpbin.org".</p>
<pre><code class="text syntaxhl" data-language="text">openssl s_client -connect httpbin.org:443
</code></pre>
<blockquote>
<p>tlsv1 alert internal error</p>
</blockquote>
<pre><code class="text syntaxhl" data-language="text">openssl s_client -connect httpbin.org:443 -servername httpbin.org
</code></pre>
<blockquote>
<p>ok</p>
</blockquote>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s2">"openssl"</span>
<span class="nb">require</span> <span class="s2">"socket"</span>
<span class="no">HOST</span> <span class="o">=</span> <span class="s2">"httpbin.org"</span>
<span class="k">class</span> <span class="nc">SSL</span> <span class="o"><</span> <span class="no">OpenSSL</span><span class="o">::</span><span class="no">SSL</span><span class="o">::</span><span class="no">SSLSocket</span>
<span class="k">def</span> <span class="nf">initialize</span> <span class="o">*</span><span class="n">args</span>
<span class="k">super</span>
<span class="vi">@hostname</span> <span class="o">=</span> <span class="no">HOST</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="n">socket</span> <span class="o">=</span> <span class="no">TCPSocket</span><span class="p">.</span><span class="nf">open</span> <span class="no">HOST</span><span class="p">,</span> <span class="mi">443</span>
<span class="k">begin</span>
<span class="n">ssl_socket</span> <span class="o">=</span> <span class="no">SSL</span><span class="p">.</span><span class="nf">new</span> <span class="n">socket</span><span class="p">,</span> <span class="no">OpenSSL</span><span class="o">::</span><span class="no">SSL</span><span class="o">::</span><span class="no">SSLContext</span><span class="p">.</span><span class="nf">new</span>
<span class="k">begin</span>
<span class="n">ssl_socket</span><span class="p">.</span><span class="nf">connect</span>
<span class="nb">puts</span> <span class="s2">"connected"</span>
<span class="k">ensure</span>
<span class="n">ssl_socket</span><span class="p">.</span><span class="nf">close</span>
<span class="k">end</span>
<span class="k">ensure</span>
<span class="n">socket</span><span class="p">.</span><span class="nf">close</span>
<span class="k">end</span>
</code></pre>
<p>This code works fine with any ruby 2.0-2.3 and rubinius, but it failed with 2.4.0 and 2.4.1.</p>
<p>I can see that you've removed accessor from <strong>lib/ruby/2.4.0/openssl/ssl.rb</strong>:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="no">ExtConfig</span><span class="o">::</span><span class="no">HAVE_TLSEXT_HOST_NAME</span>
<span class="nb">attr_reader</span> <span class="ss">:hostname</span>
<span class="k">end</span>
</code></pre>
<p><strong>ext/openssl/ossl_ssl.c</strong>:</p>
<pre><code class="c syntaxhl" data-language="c"><span class="cp">#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
</span> <span class="cm">/* #hostname is defined in lib/openssl/ssl.rb */</span>
<span class="n">rb_define_method</span><span class="p">(</span><span class="n">cSSLSocket</span><span class="p">,</span> <span class="s">"hostname="</span><span class="p">,</span> <span class="n">ossl_ssl_set_hostname</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="cp">#endif
</span></code></pre>
<p>So we have to use <strong>self.hostname = HOST</strong> instead of <strong>@hostname = HOST</strong>.</p>
<p>Please document this new behaviour in documentation. Thank you.</p>
Ruby master - Bug #7275 (Third Party's Issue): net/http wrong status line: "\x00HTTP/1.1 200 OK"
https://redmine.ruby-lang.org/issues/7275
2012-11-04T20:33:09Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<ol>
<li>install proxychains</li>
<li>proxychains irb<br>
ProxyChains-3.1 (<a href="http://proxychains.sf.net" class="external">http://proxychains.sf.net</a>)<br>
1.9.3p194 :001 > require "net/http"<br>
=> true<br>
1.9.3p194 :002 > res = Net::HTTP.start("www.google.com", "80") do |http|<br>
1.9.3p194 :003 > http.request Net::HTTP::Get.new("/")<br>
1.9.3p194 :004?> end<br>
|S-chain|-<>-112.83.231.254:6666-<><>-74.125.232.49:80-<><>-OK<br>
Net::HTTPBadResponse: wrong status line: "\x00HTTP/1.1 302 Found"<br>
from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2564:in <code>read_status_line' from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2551:in </code>read_new'<br>
from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1319:in <code>block in transport_request' from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in </code>catch'<br>
from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in <code>transport_request' from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1293:in </code>request'<br>
from (irb):3:in <code>block in irb_binding' from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in </code>start'<br>
from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:557:in <code>start' from (irb):2 from /home/puchuu/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in </code>'</li>
</ol>
Ruby master - Bug #7136 (Third Party's Issue): 1.9.3-p194 segfault with c-extension
https://redmine.ruby-lang.org/issues/7136
2012-10-10T22:45:13Z
puchuu (Andrew Aladjev)
aladjev.andrew@gmail.com
<p>file extconf.rb:</p>
<p>require "mkmf"<br>
create_makefile("variables")</p>
<p>file variables.c:</p>
<p>#include "ruby.h"</p>
<p>void Init_variables()<br>
{<br>
VALUE num, arr, str;</p>
<pre><code> num = INT2FIX ( 1024 );
rb_define_variable ( "$ext_var_num", & num );
str = rb_str_new2 ( "this is sparta!" );
rb_define_variable ( "$ext_var_str", & str );
</code></pre>
<p>}</p>
<p>file ext.rb:</p>
<p>($LOAD_PATH <<<br>
File.expand_path("../", <strong>FILE</strong>)<br>
).uniq!</p>
<p>require "variables"</p>
<p>puts $ext_var_str<br>
puts $ext_var_num</p>
<p>ruby extconf.rb && make clean && make && ruby ext.rb</p>
<p>this is sparta!<br>
ext.rb:15: [BUG] Segmentation fault<br>
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]</p>
<p>-- Control frame information -----------------------------------------------<br>
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 CFUNC :puts<br>
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :puts<br>
c:0003 p:0067 s:0006 b:0006 l:0003f8 d:0009c8 EVAL ext.rb:15<br>
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH<br>
c:0001 p:0000 s:0002 b:0002 l:0003f8 d:0003f8 TOP</p>
<p>-- Ruby level backtrace information ----------------------------------------<br>
ext.rb:15:in <code><main>' ext.rb:15:in </code>puts'<br>
ext.rb:15:in `puts'</p>
<p>-- C level backtrace information -------------------------------------------<br>
/usr/lib64/libruby19.so.1.9(+0x155ae6) [0x7fc3f5a3dae6]<br>
/usr/lib64/libruby19.so.1.9(+0x59fd3) [0x7fc3f5941fd3]<br>
/usr/lib64/libruby19.so.1.9(rb_bug+0xbb) [0x7fc3f594277b]<br>
/usr/lib64/libruby19.so.1.9(+0xf72bf) [0x7fc3f59df2bf]<br>
/lib64/libc.so.6(+0x37f80) [0x7fc3f5578f80]<br>
/usr/lib64/libruby19.so.1.9(rb_io_puts+0x90) [0x7fc3f5966bd0]<br>
/usr/lib64/libruby19.so.1.9(+0x14c192) [0x7fc3f5a34192]<br>
/usr/lib64/libruby19.so.1.9(+0x14fb93) [0x7fc3f5a37b93]<br>
/usr/lib64/libruby19.so.1.9(+0x145b69) [0x7fc3f5a2db69]<br>
/usr/lib64/libruby19.so.1.9(+0x14b1c4) [0x7fc3f5a331c4]<br>
/usr/lib64/libruby19.so.1.9(rb_iseq_eval_main+0xad) [0x7fc3f5a3a63d]<br>
/usr/lib64/libruby19.so.1.9(+0x5d80a) [0x7fc3f594580a]<br>
/usr/lib64/libruby19.so.1.9(ruby_exec_node+0x1d) [0x7fc3f59462ad]<br>
/usr/lib64/libruby19.so.1.9(ruby_run_node+0x1e) [0x7fc3f5947d3e]<br>
ruby() [0x40099b]<br>
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7fc3f55656c5]<br>
ruby() [0x4009c9]</p>