New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Socket.xs does not handle correctly UNIX domain sockets on FreeBSD #9788
Comments
From btik-fbsd@scoubidou.comThis is a bug report for perl from btik-fbsd@scoubidou.com, Bug with UNIX domain sockets on FreeBSD (at least 7.0 until 7.2 The unpack_sockaddr_un of perl-5.10.0/ext/Socket/Socket.xs does not It returns errors like: When the system returns a struct sockaddr_un in getpeername(), it In some cases, servers (X for /tmp/.X11-unix/X0 and devd for Then getpeername() returns a structure that Socket.xs One can reproduce the problem with the following simple server and Server side : use strict; my $name = $ARGV[0] or die "usage: $0 server_socket_file"; #my $sun = sockaddr_un($name); socket(my Client side (note that /var/run/devd.pipe socket is always available use strict; my $name = $ARGV[0] // '/var/run/devd.pipe'; warn "*** Connecting to $name\n"; socket(my my $sockaddr = getpeername( ($warn = $sockaddr) =~ s/([\x00-\x19\x7f-\xff])/sprintf("<%02x>",ord$1)/ge; close $fh; I join a patch that correct the problem on FreeBSD. Note that the version in the GIT repository have the same problem. Perhaps the same problem occurs on other BSD (Open, Net, DragonFly), Many thanks for your work, dont hesitate to contact me to do some Best regards, Maxime Soulé. Patch to perl-5.10.0/ext/Socket/Socket.xs : Inline Patch--- perl-5.10.0/ext/Socket/Socket.xs.orig 2009-07-07 17:29:59.000000000 +0200
+++ perl-5.10.0/ext/Socket/Socket.xs 2009-07-07 18:25:57.000000000 +0200
@@ -351,19 +351,25 @@
#ifdef I_SYS_UN
struct sockaddr_un addr;
STRLEN sockaddrlen;
+ STRLEN sockaddrmaxlen;
char * sun_ad = SvPVbyte(sun_sv,sockaddrlen);
char * e;
+# ifdef __FreeBSD__
+ sockaddrmaxlen = addr.sun_len;
+# else
+ sockaddrmaxlen = sizeof(addr);
+# endif
# ifndef __linux__
/* On Linux sockaddrlen on sockets returned by accept, recvfrom,
getpeername and getsockname is not equal to sizeof(addr). */
- if (sockaddrlen != sizeof(addr)) {
+ if (sockaddrlen != sockaddrmaxlen) {
croak("Bad arg length for %s, length is %d, should be %d",
"Socket::unpack_sockaddr_un",
- sockaddrlen, sizeof(addr));
+ sockaddrlen, sockaddrmaxlen);
}
# endif
- Copy( sun_ad, &addr, sizeof addr, char );
+ Copy( sun_ad, &addr, sockaddrmaxlen, char );
if ( addr.sun_family != AF_UNIX ) {
croak("Bad address family for %s, got %d, should be %d",
@@ -372,11 +378,18 @@
AF_UNIX);
}
e = (char*)addr.sun_path;
+# ifdef __FreeBSD__
+ /* On FreeBSD sun_path ends not always with a '\0'.
+ * How do other BSDs work? */
+ while (e < (char*)&addr + sockaddrmaxlen && *e)
+ ++e;
+# else
/* On Linux, the name of abstract unix domain sockets begins
* with a '\0', so allow this. */
while ((*e || (e == addr.sun_path && e[1] && sockaddrlen > 1))
&& e < (char*)addr.sun_path + sizeof addr.sun_path)
++e;
+# endif
ST(0) = sv_2mortal(newSVpvn(addr.sun_path, e - (char*)addr.sun_path));
#else
ST(0) = (SV *) not_here("unpack_sockaddr_un");
---
Site configuration information for perl 5.10.0: Configured by max at Wed Jun 10 09:50:59 CEST 2009. Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Locally applied patches: @INC for perl 5.10.0: Environment for perl 5.10.0: |
From @smpetersOn Tue, Jul 7, 2009 at 11:53 AM, btik-fbsd@scoubidou.com (via RT) <
I'll see if I can get a workable test script for those tomorrow once I have Steve Peters |
The RT System itself - Status changed from 'new' to 'open' |
From @tonycozOn Tue Jul 07 09:53:21 2009, maximum.solo wrote:
Hi, I can reproduce the failure with your test code on FreeBSD 9.1. Socket.xs has changed significantly since you submitted this changed, Could you please produce a new patch and submit it as a ticket to Socket? Otherwise I'll take a closer look at some point. Tony |
@tonycoz - Status changed from 'open' to 'stalled' |
From btik-fbsd@scoubidou.comHi Tony, I will try to have a look at this tonight. Stay tuned :) Best regards, Max. Le 26.06.2013 02:33, Tony Cook via RT a écrit :
|
The RT System itself - Status changed from 'stalled' to 'open' |
From btik-fbsd@scoubidou.comLe Mar. Jun. 25 17:33:17 2013, tonyc a �crit�:
Hi Tony, Done: https://rt.cpan.org/Ticket/Display.html?id=86613 Best regards, Max. |
From @tonycozOn Mon Jul 01 13:23:03 2013, maximum.solo wrote: Since this was fixed in Socket 2.011 and no longer crashes when I test Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#67298 (status was 'resolved')
Searchable as RT67298$
The text was updated successfully, but these errors were encountered: