[issue25541] Wrong usage of sockaddr_un struct for abstract namespace unix sockets

2019-05-06 Thread PrzemeK


PrzemeK  added the comment:

Yep, it was 3.4 then... but I think problem still exists

tl;dr: For abstract sockets (only?) filling struct with zeros is 
meaningful.

long:
* Python (cli) -> Python (srv) = works
* C (cli) -> C (srv) = works
* C (cli) -> Python (srv) = does NOT work
* Python (cli) -> C (srv) = does NOT work (strace dumps below)

$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0

$ uname -a
Linux ajzus 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 
x86_64 x86_64 GNU/Linux

$ python3.7 --version
Python 3.7.1


// 1st console
$ gcc -g -Wall -Wextra -pedantic -o abs_srv abs_srv.c

$ strace ./abs_srv
...
socket(AF_UNIX, SOCK_STREAM, 0) = 3
bind(3, {sa_family=AF_UNIX, 
sun_path=@"/var/tmp/sock.tmp\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"},
 110) = 0
listen(3, 5)= 0
accept(3, NULL, NULL
// waiting


// 2nd console
$ ls /var/tmp/*.sock
ls: cannot access '/var/tmp/*.sock': No such file or directory

$ strace python3.7 abs_cli.py
...
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3
connect(3, {sa_family=AF_UNIX, sun_path=@"/var/tmp/sock.tmp"}, 20) = -1 
ECONNREFUSED (Connection refused)

--
versions: +Python 3.7

___
Python tracker 
<https://bugs.python.org/issue25541>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25541] Wrong usage of sockaddr_un struct for abstract namespace unix sockets

2019-05-06 Thread PrzemeK


PrzemeK  added the comment:

Gist: https://gist.github.com/soutys/ffbe2e76a86835a9cc6b

More:

Padding `sun_path` with zeros for python cli code:
 
...
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect("\0/var/tmp/sock.tmp" + "\0" * 90)
...

gives strace like:
...
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3
connect(3, {sa_family=AF_UNIX, 
sun_path=@"/var/tmp/sock.tmp\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"},
 110) = 0
write(1, "Ready.\n", 7Ready.
) = 7
...

= works

--

___
Python tracker 
<https://bugs.python.org/issue25541>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25541] Wrong usage of sockaddr_un struct for abstract namespace unix sockets

2015-11-03 Thread PrzemeK

Changes by PrzemeK :


--
components: IO, Library (Lib)
nosy: soutys
priority: normal
severity: normal
status: open
title: Wrong usage of sockaddr_un struct for abstract namespace unix sockets
type: behavior
versions: Python 2.7, Python 3.4

___
Python tracker 
<http://bugs.python.org/issue25541>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25541] Wrong usage of sockaddr_un struct for abstract namespace unix sockets

2015-11-03 Thread PrzemeK

New submission from PrzemeK:

Case: 
http://stackoverflow.com/questions/33465094/connection-refused-when-using-abstract-namespace-unix-sockets

The code that does not work (python3 example):
...
sock_path = b"/var/tmp/sock.tmp"
server.bind(b"\0" + sock_path)
...
and strace shows:
connect(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 20) = -1 
ECONNREFUSED (Connection refused)

For C-written client strace shows:
connect(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 110) = 0

The code that actually works (python3 example):
...
sun_path_len = 108
sock_path = b"/var/tmp/sock.tmp"
server.bind(b"\0" + sock_path + (b"\0" * (sun_path_len - len(sock_path) - 1)))
...
and strace shows:
bind(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 110) = 0
110 it's the correst size of a struct.

There's no hint at 
https://docs.python.org/3/library/socket.html#socket-families for that.

Test files (servers and clients): 
https://gist.github.com/soutys/ffbe2e76a86835a9cc6b

--

___
Python tracker 
<http://bugs.python.org/issue25541>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25541] Wrong usage of sockaddr_un struct for abstract namespace unix sockets

2015-11-03 Thread PrzemeK

PrzemeK added the comment:

Errata - 1st paragraph should be:

The code that does not work (python3 example):
...
sock_path = b"/var/tmp/sock.tmp"
server.bind(b"\0" + sock_path)
...
and strace shows:
bind(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"...}, 20) = 0

--

___
Python tracker 
<http://bugs.python.org/issue25541>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com