Project

General

Profile

Actions

Bug #604

closed

Socket.pack_sockaddr_in() fails for Bignum instances of size 4

Added by raa_aars (Aravind Srinivasan) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
ruby -v:
[ruby-core:18971]

Description

=begin
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> Socket.pack_sockaddr_in(0, '192.168.1.1')
=> "\002\000\000\000\300\250\001\001\000\000\000\000\000\000\000\000"
irb(main):003:0> Socket.pack_sockaddr_in(0, 0xc0a80101)
RangeError: bignum too big to convert into long' from (irb):3:in pack_sockaddr_in'
from (irb):3
from :0
irb(main):004:0> 0xc0a80101.class
=> Bignum
irb(main):005:0> 0xc0a80101.size
=> 4

The issue might be due to implementation of ext/socket/socket.c:866: host_str() function.
The function goes like this ...
...
static char*
host_str(VALUE host, char *hbuf, size_t len)
{
if (NIL_P(host)) {
return NULL;
}
else if (rb_obj_is_kind_of(host, rb_cInteger)) {
long i = NUM2LONG(host);

     make_inetaddr(htonl(i), hbuf, len);
     return hbuf;

...

In the above snippet, i feel instead of
long i = NUM2LONG(host);
it should be
unsigned long i = NUM2ULONG(host);
as htonl accepts uint32_t.
=end

Actions #1

Updated by shyouhei (Shyouhei Urabe) over 15 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
fixed in r19593.
=end

Actions

Also available in: Atom PDF

Like0
Like0