[#74190] [Ruby trunk Feature#12134] Comparison between `true` and `false` — duerst@...
Issue #12134 has been updated by Martin D端rst.
3 messages
2016/03/07
[#74269] Type systems for Ruby — Rob Blanco <ml@...>
Dear ruby-core,
5 messages
2016/03/10
[#74395] [Ruby trunk Feature#12142] Hash tables with open addressing — shyouhei@...
Issue #12142 has been updated by Shyouhei Urabe.
3 messages
2016/03/17
[ruby-core:74655] [Ruby trunk Bug#11877] Socket.gethostname will fail when the hostname length == RUBY_MAX_HOST_NAME_LEN
From:
naruse@...
Date:
2016-03-29 05:51:22 UTC
List:
ruby-core #74655
Issue #11877 has been updated by Yui NARUSE. Backport changed from 2.1: DONE, 2.2: DONE, 2.3: REQUIRED to 2.1: DONE, 2.2: DONE, 2.3: DONE ruby_2_3 r54360 merged revision(s) 53677. ---------------------------------------- Bug #11877: Socket.gethostname will fail when the hostname length == RUBY_MAX_HOST_NAME_LEN https://bugs.ruby-lang.org/issues/11877#change-57782 * Author: Niall Sheridan * Status: Closed * Priority: Normal * Assignee: Nobuyoshi Nakada * ruby -v: * Backport: 2.1: DONE, 2.2: DONE, 2.3: DONE ---------------------------------------- When `Socket.gethostname` calls `gethostname()` with a buffer `buf`, the buffer is incorrectly sized (at least on Linux systems). `RUBY_MAX_HOST_NAME_LEN` is defined as `HOST_NAME_MAX` and the buffer `buf` is sized as `RUBY_MAX_HOST_NAME_LEN + 1`. But when `gethostname()` is called, the size parameter is passed as `sizeof buf -1`. In effect, `gethostname` is called with `RUBY_MAX_HOST_NAME_LEN` as the size of the receiving buffer. The string returned by `gethostname()` _includes_ the null-terminating character, so the receiving buffer must be sized accordingly. Because `buf` is created as `buf[RUBY_MAX_HOST_NAME_LEN+1]` it's adequately sized to hold the hostname and null terminator, but actual call is `gethostname(buf, (int)sizeof buf - 1)`. This means that if the length of the hostname is equal to the max hostname length then the call to `gethostname()` will fail as it will not have space for the null terminator. This can be seen on Linux which has a 64 character limit on hostnames: Setting a 64 character hostname: ~~~ $ hostname abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 $ hostname abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 $ irb irb(main):001:0> require 'socket' => true irb(main):002:0> Socket.gethostname Errno::ENAMETOOLONG: File name too long - gethostname from (irb):2:in `gethostname' from (irb):2 from /usr/local/bin/irb:12:in `<main>' ~~~ Setting a 63 character hostname: ~~~ $ hostname abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0 $ hostname abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0 $ irb irb(main):001:0> require 'socket' => true irb(main):002:0> Socket.gethostname => "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0" irb(main):003:0> Socket.gethostname.length => 63 ~~~ The attached patch uses the correctly sized buffer to hold the full hostname, including the null terminator that gethostname() includes. ---Files-------------------------------- hostname_size.patch (408 Bytes) -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>