classification
Title: socket.getsockname() type mismatch with AF_UNIX on Linux
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, giampaolo.rodola, ned.deily, neologix, pitrou, ronaldoussoren, vstinner
Priority: normal Keywords:

Created on 2017-04-29 08:55 by giampaolo.rodola, last changed 2017-05-02 22:23 by pitrou. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1370 merged pitrou, 2017-05-01 21:39
PR 1404 merged pitrou, 2017-05-02 22:04
PR 1403 merged pitrou, 2017-05-02 22:05
Messages (11)
msg292580 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2017-04-29 08:55
>>> import socket
>>> s = socket.socket(socket.AF_UNIX)
>>> s.getsockname()
b''
>>> s.bind('foo')
>>> s.getsockname()
'foo'
msg292581 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2017-04-29 09:03
The change was introduced here:
https://github.com/python/cpython/commit/b10c71daa2099c450101e5854fd693a405bec49c
msg292702 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-01 21:37
Amusingly, binding to the empty string produces something different:

>>> s = socket.socket(socket.AF_UNIX)
>>> s.getsockname()
b''
>>> s.bind(b'')
>>> s.getsockname()
b'\x000005d'

while binding to the nul byte string produces the expected result:

>>> s = socket.socket(socket.AF_UNIX)
>>> s.bind(b'\x00')
>>> s.getsockname()
b'\x00'
msg292776 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-02 15:20
New changeset 495b5021e73e3c4b6404417ecf4fa83aa10297f0 by Antoine Pitrou in branch 'master':
bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux (#1370)
https://github.com/python/cpython/commit/495b5021e73e3c4b6404417ecf4fa83aa10297f0
msg292781 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2017-05-02 15:38
Thanks.
msg292806 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-02 21:19
Test fails on  x86 Tiger 3.x:

http://buildbot.python.org/all/builders/x86%20Tiger%203.x/builds/600/steps/test/logs/stdio

======================================================================
FAIL: testUnbound (test.test_socket.TestUnixDomain)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/test_socket.py", line 4687, in testUnbound
    self.assertEqual(self.sock.getsockname(), '')
AssertionError: None != ''
msg292807 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-02 21:20
Maybe restrict the unit test to Linux since the change was specific to Linux?
msg292809 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-02 21:27
Oh, yuck.

> Maybe restrict the unit test to Linux since the change was specific to Linux?

That sounds reasonable.  I didn't know getsockname() could return None...
msg292810 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-05-02 21:32
> I didn't know getsockname() could return None...

Me neither. Maybe it's a bug? makesockaddr() returns None if addrlen equals 0:                                   
             
    if (addrlen == 0) {                                                           
        /* No address -- may be recvfrom() from known socket */                   
        Py_RETURN_NONE;                                                           
    }
msg292818 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-02 22:14
New changeset 0c2ff0898db2db9cd9c643dfadbff11761bacf5f by Antoine Pitrou in branch '3.6':
Backport bpo-30205 to 3.6 (#1403)
https://github.com/python/cpython/commit/0c2ff0898db2db9cd9c643dfadbff11761bacf5f
msg292819 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-05-02 22:22
New changeset 0d9d61828bbd6cbc289489bf1d439fa91eca3743 by Antoine Pitrou in branch '3.5':
Backport bpo-30205 to 3.5 (#1404)
https://github.com/python/cpython/commit/0d9d61828bbd6cbc289489bf1d439fa91eca3743
History
Date User Action Args
2017-05-02 22:23:04pitrousetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2017-05-02 22:22:30pitrousetmessages: + msg292819
2017-05-02 22:14:31pitrousetmessages: + msg292818
2017-05-02 22:05:32pitrousetpull_requests: + pull_request1512
2017-05-02 22:04:08pitrousetpull_requests: + pull_request1511
2017-05-02 21:32:09vstinnersetmessages: + msg292810
2017-05-02 21:27:12pitrousetnosy: + ronaldoussoren, ned.deily
messages: + msg292809
2017-05-02 21:20:26vstinnersetmessages: + msg292807
2017-05-02 21:19:32vstinnersetnosy: + vstinner
messages: + msg292806
2017-05-02 15:38:11giampaolo.rodolasetmessages: + msg292781
2017-05-02 15:20:04pitrousetmessages: + msg292776
2017-05-01 21:52:13christian.heimessetnosy: + christian.heimes
2017-05-01 21:39:43pitrousetpull_requests: + pull_request1479
2017-05-01 21:37:09pitrousettype: behavior
components: + Library (Lib)
versions: + Python 3.5, Python 3.6, Python 3.7, - Python 2.7
nosy: + pitrou

messages: + msg292702
stage: needs patch
2017-04-29 09:03:15giampaolo.rodolasetnosy: + neologix

messages: + msg292581
versions: + Python 2.7
2017-04-29 08:55:10giampaolo.rodolacreate