servalproject / serval-dna

The Serval Project's core daemon that implements Distributed Numbering Architecture (DNA), MDP, VoMP, Rhizome, MeshMS, etc.
http://servalproject.org
Other
170 stars 81 forks source link

OS X Instancepath related bug: no NUL terminator #104

Closed gh0st42 closed 8 years ago

gh0st42 commented 8 years ago

Cannot use SERVALINSTANCE_PATH on OSX at the moment. Compiled prefixpath seems to work.

$ export SERVALINSTANCE_PATH=/tmp/servalinstancepath
$ rm -r /tmp/servalinstancepath/
16-05-07 14:54:10 +0200
INFO: Serval DNA version: START-3478-g8e223b5
WARN: conf.c:64:reload()  config file /tmp/servalinstancepath/serval.conf does not exist -- using all defaults
WARN: No network interfaces configured (empty 'interfaces' config option)
instancepath:/tmp/servalinstancepath
pidfile:/tmp/servalinstancepath/servald.pid
pid:10335
http_port:4111
mdp_inet_port:0

$ bin/servald-darwin id self
INFO: Local date/time: 2016-05-07 14:54:35 +0200
INFO: Serval DNA version: START-3478-g8e223b5
WARN: conf.c:64:reload()  config file /tmp/servalinstancepath/serval.conf does not exist -- using all defaults
1
sid
ERROR:mdp_client.c:349:overlay_mdp_recv()  reply did not come from server: AF_UNIX:"/tmp/servalinstancepath/mdp.socket\xff" (addrlen=36, no nul terminator)

ERROR:network_cli.c:380:app_id_self()    MDP Server error #1: 'Timeout waiting for reply to MDP packet (packet was successfully sent).'
ERROR:network_cli.c:384:app_id_self()  Failed to get local address list

$ uname -a
Darwin jupiter 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

Funny thing is, without SERVALINSTANCE_PATH set it all works.

$ unset SERVALINSTANCE_PATH
$ echo $SERVALINSTANCE_PATH

$ bin/servald-darwin start
INFO: Local date/time: 2016-05-07 14:57:54 +0200
INFO: Serval DNA version: START-3478-g8e223b5
WARN: conf.c:64:reload()  config file /Users/gh0st/serval-conf/etc/serval/serval.conf does not exist -- using all defaults
WARN: No network interfaces configured (empty 'interfaces' config option)
pidfile:/Users/gh0st/serval-conf/var/run/serval/servald.pid
pid:10361
http_port:4112
mdp_inet_port:0

$ bin/servald-darwin id self
INFO: Local date/time: 2016-05-07 14:58:01 +0200
INFO: Serval DNA version: START-3478-g8e223b5
WARN: conf.c:64:reload()  config file /Users/gh0st/serval-conf/etc/serval/serval.conf does not exist -- using all defaults
1
sid
C25D7DB5F074A880467CFEF57A80E300432D19F8EBAB8C785C4F5696DD81C15F
lakeman commented 8 years ago

Can you turn on debug.io and paste the log?

Hang on, this looks a bit off https://github.com/servalproject/serval-dna/blob/development/socket.c#L290;

Should that be; ... .msg_namelen = sizeof(struct socket_address), ... bzero(&address->addr, sizeof(struct socket_address));

?

On Sat, May 7, 2016 at 10:33 PM, gh0st42 notifications@github.com wrote:

Cannot use SERVALINSTANCE_PATH on OSX at the moment. Compiled prefixpath seems to work.

$ export SERVALINSTANCE_PATH=/tmp/servalinstancepath $ rm -r /tmp/servalinstancepath/ 16-05-07 14:54:10 +0200 INFO: Serval DNA version: START-3478-g8e223b5 WARN: conf.c:64:reload() config file /tmp/servalinstancepath/serval.conf does not exist -- using all defaults WARN: No network interfaces configured (empty 'interfaces' config option) instancepath:/tmp/servalinstancepath pidfile:/tmp/servalinstancepath/servald.pid pid:10335 http_port:4111 mdp_inet_port:0

$ bin/servald-darwin id self INFO: Local date/time: 2016-05-07 14:54:35 +0200 INFO: Serval DNA version: START-3478-g8e223b5 WARN: conf.c:64:reload() config file /tmp/servalinstancepath/serval.conf does not exist -- using all defaults 1 sid ERROR:mdp_client.c:349:overlay_mdp_recv() reply did not come from server: AF_UNIX:"/tmp/servalinstancepath/mdp.socket\xff" (addrlen=36, no nul terminator)

ERROR:network_cli.c:380:app_id_self() MDP Server error #1: 'Timeout waiting for reply to MDP packet (packet was successfully sent).' ERROR:network_cli.c:384:app_id_self() Failed to get local address list

$ uname -a Darwin jupiter 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

Funny thing is, without SERVALINSTANCE_PATH set it all works.

$ unset SERVALINSTANCE_PATH $ echo $SERVALINSTANCE_PATH

$ bin/servald-darwin start INFO: Local date/time: 2016-05-07 14:57:54 +0200 INFO: Serval DNA version: START-3478-g8e223b5 WARN: conf.c:64:reload() config file /Users/gh0st/serval-conf/etc/serval/serval.conf does not exist -- using all defaults WARN: No network interfaces configured (empty 'interfaces' config option) pidfile:/Users/gh0st/serval-conf/var/run/serval/servald.pid pid:10361 http_port:4112 mdp_inet_port:0

$ bin/servald-darwin id self INFO: Local date/time: 2016-05-07 14:58:01 +0200 INFO: Serval DNA version: START-3478-g8e223b5 WARN: conf.c:64:reload() config file /Users/gh0st/serval-conf/etc/serval/serval.conf does not exist -- using all defaults 1 sid C25D7DB5F074A880467CFEF57A80E300432D19F8EBAB8C785C4F5696DD81C15F

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/servalproject/serval-dna/issues/104

gh0st42 commented 8 years ago

Here ist the output of debug.io=true serval-20160507160000.txt

gh0st42 commented 8 years ago

Changing these lines in socket.c didn't fix the problem..

lakeman commented 8 years ago

Well, that was a bit of a guess, (and so's this...)

The problem might be here; https://github.com/servalproject/serval-dna/blob/a5ff0ed2a31e33051746d86d68ba96d46c13480d/socket.c#L58

It seems that OSX has a different definition for struct sockaddr_un; http://idletechnology.blogspot.com.au/2011/12/unix-domain-sockets-on-osx.html

So we'll need to be more careful to measure the used bytes in the structure. There apparently should by a SUN_LEN macro we can use like;

addr->addrlen=SUN_LEN(&addr->local);

And here; https://github.com/servalproject/serval-dna/blob/a5ff0ed2a31e33051746d86d68ba96d46c13480d/simulator.c#L167

On Sun, May 8, 2016 at 12:37 AM, gh0st42 notifications@github.com wrote:

Changing these lines in socket.c didn't fix the problem..

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/servalproject/serval-dna/issues/104#issuecomment-217643164

gh0st42 commented 8 years ago

Hm, after playing around a bit today I'm not able to reproduce the bug at the moment. Still, using SUN_LEN macro seems the right way to get the length in a platform independent way. At least on OSX it seams to work without breaking anything else.