You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the path for a UNIXSocket (or UNIXServer) is null, attempting to retrieve the path will raise a Java error. The error is due to us not checking for null before we attempt to create the string, but the proper handling would be to use getsockname syscall against the file descriptor to get the original path.
This breaks the UNIXServer#for_fd spec, because the newly-created socket does not inherit whatever path the original file descriptor was opened against.
This probably should be fixed in jnr-unixsocket, but a workaround in JRuby would be to bind getsockname and use it like CRuby does in the implementation of UNIXSocket#path.
A rough patch shows the general change needed, but without sockaddr_in and getsockname it can't be completed currently:
diff --git a/core/src/main/java/org/jruby/ext/socket/RubyUNIXServer.java b/core/src/main/java/org/jruby/ext/socket/RubyUNIXServer.java
index a936898a4d..6c288cf4ce 100644
--- a/core/src/main/java/org/jruby/ext/socket/RubyUNIXServer.java+++ b/core/src/main/java/org/jruby/ext/socket/RubyUNIXServer.java@@ -156,11 +156,6 @@ public class RubyUNIXServer extends RubyUNIXSocket {
return context.runtime.newFixnum(((UnixSocketChannel) socket.getChannel()).getFD());
}
- @JRubyMethod- public IRubyObject path(ThreadContext context) {- return context.runtime.newString(openFile.getPath());- }-
@JRubyMethod
public IRubyObject addr(ThreadContext context) {
Ruby runtime = context.runtime;
diff --git a/core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java b/core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java
index 0c8577739c..0b26d8f51f 100644
--- a/core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java+++ b/core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java@@ -103,7 +103,13 @@ public class RubyUNIXSocket extends RubyBasicSocket {
@JRubyMethod
public IRubyObject path(ThreadContext context) {
- return RubyString.newEmptyString(context.runtime);+ String path = openFile.getPath();++ if (path == null) {+ // cruby does getsockname here to get the name from fileno+ }++ return context.runtime.newString(path);
}
@JRubyMethod
The text was updated successfully, but these errors were encountered:
Found during spec update in #8087.
When the path for a UNIXSocket (or UNIXServer) is null, attempting to retrieve the path will raise a Java error. The error is due to us not checking for null before we attempt to create the string, but the proper handling would be to use
getsockname
syscall against the file descriptor to get the original path.This breaks the UNIXServer#for_fd spec, because the newly-created socket does not inherit whatever path the original file descriptor was opened against.
This probably should be fixed in jnr-unixsocket, but a workaround in JRuby would be to bind
getsockname
and use it like CRuby does in the implementation of UNIXSocket#path.A rough patch shows the general change needed, but without sockaddr_in and getsockname it can't be completed currently:
The text was updated successfully, but these errors were encountered: