mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
socket.c: null byte at Socket.getnameinfo
* ext/socket/socket.c (sock_s_getnameinfo): check null byte. patched by tommy (Masahiro Tomita) in [ruby-dev:50286]. [Bug #13994] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0c551b7a6d
commit
fb89004a3b
2 changed files with 4 additions and 2 deletions
|
@ -1287,7 +1287,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
|
|||
hptr = NULL;
|
||||
}
|
||||
else {
|
||||
strncpy(hbuf, StringValuePtr(host), sizeof(hbuf));
|
||||
strncpy(hbuf, StringValueCStr(host), sizeof(hbuf));
|
||||
hbuf[sizeof(hbuf) - 1] = '\0';
|
||||
hptr = hbuf;
|
||||
}
|
||||
|
@ -1301,7 +1301,7 @@ sock_s_getnameinfo(int argc, VALUE *argv)
|
|||
pptr = pbuf;
|
||||
}
|
||||
else {
|
||||
strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));
|
||||
strncpy(pbuf, StringValueCStr(port), sizeof(pbuf));
|
||||
pbuf[sizeof(pbuf) - 1] = '\0';
|
||||
pptr = pbuf;
|
||||
}
|
||||
|
|
|
@ -105,6 +105,8 @@ class TestSocket < Test::Unit::TestCase
|
|||
|
||||
def test_getnameinfo
|
||||
assert_raise(SocketError) { Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) }
|
||||
assert_raise(ArgumentError) {Socket.getnameinfo(["AF_INET", "http\0", "example.net"])}
|
||||
assert_raise(ArgumentError) {Socket.getnameinfo(["AF_INET", "http", "example.net\0"])}
|
||||
end
|
||||
|
||||
def test_ip_address_list
|
||||
|
|
Loading…
Add table
Reference in a new issue