From: Martin Bosslet Date: 2011-10-19T01:37:06+09:00 Subject: [ruby-core:40215] [Ruby 1.9 - Bug #5233] OpenSSL::SSL::SSLSocket has problems with encodings other than "ascii" Issue #5233 has been updated by Martin Bosslet. The problem is in lib/openssl/buffering.rb: def do_write(s) @wbuffer = "" unless defined? @wbuffer @wbuffer << s @sync ||= false if @sync or @wbuffer.size > BLOCK_SIZE or idx = @wbuffer.rindex($/) remain = idx ? idx + $/.size : @wbuffer.length nwritten = 0 while remain > 0 str = @wbuffer[nwritten,remain] begin nwrote = syswrite(str) rescue Errno::EAGAIN retry end remain -= nwrote nwritten += nwrote end @wbuffer[0,nwritten] = "" end end remain gets initialized with @wbuffer.length, the string length in characters, but nwrote receives the actual number of bytes written, so less bytes than actually available are written. A fix for this would be treating @wbuffer strictly as binary data by forcing its encoding to BINARY. I'm not sure, does anyone see a more elegant way or would this solution suffice? ---------------------------------------- Bug #5233: OpenSSL::SSL::SSLSocket has problems with encodings other than "ascii" http://redmine.ruby-lang.org/issues/5233 Author: Niklas Baumstark Status: Assigned Priority: Normal Assignee: Martin Bosslet Category: ext Target version: 1.9.4 ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux] The attached script shows the issue. It expects a combined cert/private key in the file server.pem under the current directory (also attached). Under Ruby 1.9.2p290, the script prints "str.size is 50848 (expecting 100000)". As a workaround the string encoding can be forced to "ascii" before the write. -- http://redmine.ruby-lang.org