summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/lib/socket.rb2
-rw-r--r--ext/socket/raddrinfo.c6
2 files changed, 6 insertions, 2 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 981b937329..540b01804e 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -819,7 +819,7 @@ class Socket < BasicSocket
private
def unix_socket_abstract_name?(path)
- /linux/ =~ RUBY_PLATFORM && /\A\0/ =~ path
+ /linux/ =~ RUBY_PLATFORM && /\A(\0|\z)/ =~ path
end
end
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 79943c79e2..a730a1b4c4 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -446,7 +446,11 @@ socklen_t
rsock_unix_sockaddr_len(VALUE path)
{
#ifdef __linux__
- if (RSTRING_PTR(path)[0] == '\0') {
+ if (RSTRING_LEN(path) == 0) {
+ /* autobind; see unix(7) for details. */
+ return (socklen_t) sizeof(sa_family_t);
+ }
+ else if (RSTRING_PTR(path)[0] == '\0') {
/* abstract namespace; see unix(7) for details. */
return (socklen_t) offsetof(struct sockaddr_un, sun_path) +
RSTRING_LEN(path);