[erlang-questions] unix domain sockets with abstract namespace: can't use all 108 bytes

Bekes, Andras G <>
Wed Apr 19 14:13:26 CEST 2017


Did anyone have a chance to take a closer look?

I still think that this is a bug in Erlang.

From: Bekes, Andras G (IST)
Sent: Tuesday, March 28, 2017 9:55 AM
To: 'Alex S.'
Cc: 
Subject: RE: [erlang-questions] unix domain sockets with abstract namespace: can't use all 108 bytes

I was also thinking about how and why Erlang puts its limit at 107 characters, but regardless of the answers, apparently I need to use 108 bytes, which seems to be a valid thing on Linux.
Note: I need to see the number 110 passed as the 3rd parameter to the connect syscall, as opposed to 109.

From: Alex S. [mailto:]
Sent: Monday, March 27, 2017 8:00 PM
To: Bekes, Andras G (IST)
Cc: 
Subject: Re: [erlang-questions] unix domain sockets with abstract namespace: can't use all 108 bytes

I have a strong suspicion the binary might be automatically zero-terminated.
27 марта 2017 г., в 19:03, Bekes, Andras G <<mailto:>> написал(а):


Hi All,

I need to communicate with unix domain sockets using the abstract namespace and the server (which is not under my control) opens the port with all 108 bytes of the path used.
If I understand it correctly, the server/client can decide to indicate the number of actual bytes used in the 3rd parameter to the bind/connect syscalls (this what Erlang does), but it is also possible to use all 108 bytes and fill the unused part with 0 bytes (this is what my server does).
http://man7.org/linux/man-pages/man7/unix.7.html

Apparently, I can fill the path with 0 bytes up to 107 only. If I try to pass a 108-byte address to gen_tcp:connect, I get a badarg exception:

> Sun_path_length=108.
108

> UDS_path = <<"whatever">>.
<<"whatever">>

> Fill_length = 8*(Sun_path_length-byte_size(UDS_path)-1).
792

> Address = {local,<<0, UDS_path/binary,0:Fill_length>>}.
{local,<<0,119,104,97,116,101,118,101,114,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,...>>}

> Port = 0.
0

> gen_tcp:connect(Address,Port,[local],infinity).
(<0.236.0>) call gen_tcp:connect({local,<<0,119,104,97,116,101,118,101,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,0,0>>},0,[local],infinity)
(<0.236.0>) call gen_tcp:connect1({local,<<0,119,104,97,116,101,118,101,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
         0,0,0,0,0,0,0,0,0,0,0,0,0>>},0,[local],false)
(<0.236.0>) call gen_tcp:try_connect([{local,<<0,119,104,97,116,101,118,101,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>}],0,[],false,local_tcp,{error,einval})
(<0.236.0>) returned from gen_tcp:try_connect/6 -> {error,einval}
** exception exit: badarg
     in function  gen_tcp:connect/4 (gen_tcp.erl, line 149)
(<0.236.0>) returned from gen_tcp:connect1/4 -> {error,einval}
(<0.236.0>) exception_from {gen_tcp,connect,4} {exit,badarg}

If I reduce the path to 107 bytes, it works. With strace, I can see the connect syscall:
connect(19, {sa_family=AF_FILE, path=@"whatever"...}, 109) = -1 ECONNREFUSED (Connection refused)
When I strace the official client of this server, the 3rd parameter to the connect syscall is 110 (108 + 2), regardless of the actual length of the path.

Apparently, with Erlang it is not possible to use all 108 bytes. I should only get a badarg error at 109 bytes, not 108.
Seems to me that this is a bug in the Erlang implementation. What do you think?

Thank you very much,

Andras G. Bekes, Vice President
Morgan Stanley | Institutional Securities Tech
Lechner Odon Fasor 6 | Floor 06
Budapest, 1095
Phone: +36 1 882-0791
<mailto:>


________________________________

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers  If you cannot access these links, please notify us by reply message and we will send the contents to you. By communicating with Morgan Stanley you consent to the foregoing and to the voice recording of conversations with personnel of Morgan Stanley.





_______________________________________________
erlang-questions mailing list
<mailto:>
http://erlang.org/mailman/listinfo/erlang-questions



________________________________

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers  If you cannot access these links, please notify us by reply message and we will send the contents to you. By communicating with Morgan Stanley you consent to the foregoing and to the voice recording of conversations with personnel of Morgan Stanley.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170419/0cc902cd/attachment.html>


More information about the erlang-questions mailing list