1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/socket.c (sock_s_unpack_sockaddr_in): check too short

sockaddr.
  (sock_s_unpack_sockaddr_un): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-01-12 16:00:03 +00:00
parent 73757753ae
commit 91ff87c05d
3 changed files with 18 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Tue Jan 13 00:57:56 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (sock_s_unpack_sockaddr_in): check too short
sockaddr.
(sock_s_unpack_sockaddr_un): ditto.
Mon Jan 12 23:55:19 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (addrinfo_ip_unpack): new method

View file

@ -4328,6 +4328,11 @@ sock_s_unpack_sockaddr_in(VALUE self, VALUE addr)
VALUE host;
sockaddr = (struct sockaddr_in*)SockAddrStringValuePtr(addr);
if (RSTRING_LEN(addr) <
(char*)&((struct sockaddr *)sockaddr)->sa_family +
sizeof(((struct sockaddr *)sockaddr)->sa_family) -
(char*)sockaddr)
rb_raise(rb_eArgError, "too short sockaddr");
if (((struct sockaddr *)sockaddr)->sa_family != AF_INET
#ifdef INET6
&& ((struct sockaddr *)sockaddr)->sa_family != AF_INET6
@ -4397,6 +4402,11 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
VALUE path;
sockaddr = (struct sockaddr_un*)SockAddrStringValuePtr(addr);
if (RSTRING_LEN(addr) <
(char*)&((struct sockaddr *)sockaddr)->sa_family +
sizeof(((struct sockaddr *)sockaddr)->sa_family) -
(char*)sockaddr)
rb_raise(rb_eArgError, "too short sockaddr");
if (((struct sockaddr *)sockaddr)->sa_family != AF_UNIX) {
rb_raise(rb_eArgError, "not an AF_UNIX sockaddr");
}

View file

@ -93,6 +93,8 @@ class TestSocket < Test::Unit::TestCase
assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(sockaddr_in) }
sockaddr_un = Socket.sockaddr_un("/tmp/s")
assert_raise(ArgumentError) { Socket.unpack_sockaddr_in(sockaddr_un) }
assert_raise(ArgumentError) { Socket.unpack_sockaddr_in("") }
assert_raise(ArgumentError) { Socket.unpack_sockaddr_un("") }
end if Socket.respond_to?(:sockaddr_un)
def test_sysaccept