mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
* ext/socket/raddrinfo.c (rsock_unixpath_len, init_unix_addrinfo),
ext/socket/unixsocket.c (unixsock_connect_internal, rsock_init_unixsock): calculate the correct address length of an abstract socket. Without this fix, sizeof(struct sockaddr_un) is specified as the length of an abstract socket for bind(2) or connect(2), so the address of the socket is filled with extra NUL characters. See unix(7) for details. * ext/socket/lib/socket.rb (unix_server_socket): don't access the file system if the platform is Linux and path starts with NUL, which means that the socket is an abstract socket. * test/socket/test_unix.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
76ade818ae
commit
ad55d141eb
6 changed files with 92 additions and 10 deletions
|
@ -13,6 +13,7 @@
|
|||
#ifdef HAVE_SYS_UN_H
|
||||
struct unixsock_arg {
|
||||
struct sockaddr_un *sockaddr;
|
||||
socklen_t sockaddrlen;
|
||||
int fd;
|
||||
};
|
||||
|
||||
|
@ -21,13 +22,14 @@ unixsock_connect_internal(VALUE a)
|
|||
{
|
||||
struct unixsock_arg *arg = (struct unixsock_arg *)a;
|
||||
return (VALUE)rsock_connect(arg->fd, (struct sockaddr*)arg->sockaddr,
|
||||
(socklen_t)sizeof(*arg->sockaddr), 0);
|
||||
arg->sockaddrlen, 0);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
||||
{
|
||||
struct sockaddr_un sockaddr;
|
||||
socklen_t sockaddrlen;
|
||||
int fd, status;
|
||||
rb_io_t *fptr;
|
||||
|
||||
|
@ -44,14 +46,16 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
|||
RSTRING_LEN(path), (int)sizeof(sockaddr.sun_path));
|
||||
}
|
||||
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
||||
sockaddrlen = rsock_unixpath_len(path);
|
||||
|
||||
if (server) {
|
||||
status = bind(fd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr));
|
||||
status = bind(fd, (struct sockaddr*)&sockaddr, sockaddrlen);
|
||||
}
|
||||
else {
|
||||
int prot;
|
||||
struct unixsock_arg arg;
|
||||
arg.sockaddr = &sockaddr;
|
||||
arg.sockaddrlen = sockaddrlen;
|
||||
arg.fd = fd;
|
||||
status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
|
||||
if (prot) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue