mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr
instead of (Safe)StringValue, to detect NUL byte in the string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
77a8772b11
commit
3912e4fa3b
3 changed files with 17 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue May 31 00:30:11 2016 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr
|
||||||
|
instead of (Safe)StringValue, to detect NUL byte in the string.
|
||||||
|
|
||||||
Mon May 30 22:02:01 2016 Kazuki Yamaguchi <k@rhe.jp>
|
Mon May 30 22:02:01 2016 Kazuki Yamaguchi <k@rhe.jp>
|
||||||
|
|
||||||
* ext/openssl/ossl_asn1.c (time_to_time_t): Use NUM2TIMET() instead of
|
* ext/openssl/ossl_asn1.c (time_to_time_t): Use NUM2TIMET() instead of
|
||||||
|
|
|
@ -429,6 +429,10 @@ str_is_number(const char *p)
|
||||||
#define str_equal(ptr, len, name) \
|
#define str_equal(ptr, len, name) \
|
||||||
((ptr)[0] == name[0] && \
|
((ptr)[0] == name[0] && \
|
||||||
rb_strlen_lit(name) == (len) && memcmp(ptr, name, len) == 0)
|
rb_strlen_lit(name) == (len) && memcmp(ptr, name, len) == 0)
|
||||||
|
#define SafeStringValueCStr(v) do {\
|
||||||
|
StringValueCStr(v);\
|
||||||
|
rb_check_safe_obj(v);\
|
||||||
|
} while(0)
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr)
|
host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr)
|
||||||
|
@ -447,7 +451,7 @@ host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr)
|
||||||
const char *name;
|
const char *name;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
SafeStringValue(host);
|
SafeStringValueCStr(host);
|
||||||
RSTRING_GETMEM(host, name, len);
|
RSTRING_GETMEM(host, name, len);
|
||||||
if (!len || str_equal(name, len, "<any>")) {
|
if (!len || str_equal(name, len, "<any>")) {
|
||||||
make_inetaddr(INADDR_ANY, hbuf, hbuflen);
|
make_inetaddr(INADDR_ANY, hbuf, hbuflen);
|
||||||
|
@ -486,7 +490,7 @@ port_str(VALUE port, char *pbuf, size_t pbuflen, int *flags_ptr)
|
||||||
const char *serv;
|
const char *serv;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
SafeStringValue(port);
|
SafeStringValueCStr(port);
|
||||||
RSTRING_GETMEM(port, serv, len);
|
RSTRING_GETMEM(port, serv, len);
|
||||||
if (len >= pbuflen) {
|
if (len >= pbuflen) {
|
||||||
rb_raise(rb_eArgError, "service name too long (%"PRIdSIZE")",
|
rb_raise(rb_eArgError, "service name too long (%"PRIdSIZE")",
|
||||||
|
|
|
@ -42,6 +42,9 @@ class TestSocketAddrinfo < Test::Unit::TestCase
|
||||||
Addrinfo.ip(addr)
|
Addrinfo.ip(addr)
|
||||||
end
|
end
|
||||||
assert_equal([0, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
assert_equal([0, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
Addrinfo.ip("127.0.0.1\000x")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addrinfo_tcp
|
def test_addrinfo_tcp
|
||||||
|
@ -56,6 +59,9 @@ class TestSocketAddrinfo < Test::Unit::TestCase
|
||||||
Addrinfo.tcp("127.0.0.1", "0000000000000000000000080x".chop)
|
Addrinfo.tcp("127.0.0.1", "0000000000000000000000080x".chop)
|
||||||
end
|
end
|
||||||
assert_equal([80, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
assert_equal([80, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
Addrinfo.ip("127.0.0.1", "80\000x")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_addrinfo_udp
|
def test_addrinfo_udp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue