[Mono-bugs] [Bug 79084][Nor] New - socket-io.c and UnixEndPoint have broken assumptions

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Aug 16 07:16:49 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by alp at atoker.com.

http://bugzilla.ximian.com/show_bug.cgi?id=79084

--- shadow/79084	2006-08-16 07:16:49.000000000 -0400
+++ shadow/79084.tmp.10842	2006-08-16 07:16:49.000000000 -0400
@@ -0,0 +1,88 @@
+Bug#: 79084
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: io-layer
+AssignedTo: dick at ximian.com                            
+ReportedBy: alp at atoker.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: socket-io.c and UnixEndPoint have broken assumptions
+
+socket-io.c has
+
+*sa_size = sizeof (struct sockaddr_un);
+
+This means that sa_size always ends up being 110 (108 + 2 bytes for the
+address family?).
+
+The result is that we pass junk as part of the socket address when
+sa_family == AF_UNIX.
+
+An strace shows something like:
+
+socket(PF_FILE, SOCK_STREAM, 0)         = 3
+connect(3, {sa_family=AF_FILE, path="/tmp/foo"}, 110) = 0
+
+It should really be more like:
+
+socket(PF_FILE, SOCK_STREAM, 0)         = 3
+connect(3, {sa_family=AF_FILE, path="/tmp/foo"}, 9) = 0
+
+This is because "/tmp/foo\0".Length = 9
+
+It has not been a major problem in the past as there are hacks to the
+managed side (UnixEndPoint in Mono.Unix) to make things appear to work in
+some cases.
+
+The problem was discovered when implementing a program that needs to use
+abstract domain sockets.
+
+In abstract domain sockets, the socket address data payload is prefixed
+with null _instead_ of being suffixed with null. See unix(7) for the lowdown.
+
+In order to allow for the managed code to support abstract domain sockets,
+and not to break hashing in the general case, it is important to
+
+(1) Set the correct length:
+*sa_size = len;
+
+(2) Remove the unmanaged null termination
+-		sock_un->sun_path [len - 2] = '\0';
+
+(3) Optional exercise: Review this:
+data=mono_array_new(domain, mono_get_byte_class (), sa_size - 2);
+
+Should the - 2 really be there? Maybe, have not thought that far ahead.
+
+
+The null suffix/prefix should instead be added properly in the managed code
+in UnixEndPoint, so we can later add a class called AbstractUnixEndPoint or
+otherwise add support for null prefixing and the abstract namespace.
+
+Once this area is clarified, we also need to look at whether we really want
+to +=2 when marshaling in the opposite direction. Hopefully one day we will
+have tests for this as well, but it doesn't make sense to write tests until
+we understand what's required.
+
+A concept patch for the unmanaged side is attached. This is the most
+important modification for my needs, since without it, managed code never
+has even a chance of using abstract sockets, whereas with it, I can at
+least bundle a fixed UnixEndPoint with my code and require the latest fixed
+Mono release. However, it would be good to clean up the hacks in
+UnixEndPoint now that we have this part cleared up.
+
+strace is the key tool for debugging this. The only consumer of abstract
+sockets I know of that's readily available is dbus-send:
+
+strace dbus-send --system --print-reply=literal --dest=org.freedesktop.DBus
+/org/freedesktop/DBus org.freedesktop.DBus.NameHasOwner string:foo
+
+One expects that it's getting things right.


More information about the mono-bugs mailing list