Skip to content
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.getsockname() type mismatch with AF_UNIX on Linux #74391

Closed
giampaolo opened this issue Apr 29, 2017 · 11 comments
Closed

socket.getsockname() type mismatch with AF_UNIX on Linux #74391

giampaolo opened this issue Apr 29, 2017 · 11 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@giampaolo
Copy link
Contributor

BPO 30205
Nosy @ronaldoussoren, @pitrou, @vstinner, @giampaolo, @tiran, @ned-deily
PRs
  • bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux #1370
  • Backport bpo-30205 to 3.5 #1404
  • Backport bpo-30205 to 3.6 #1403
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-05-02.22:23:04.258>
    created_at = <Date 2017-04-29.08:55:10.959>
    labels = ['3.7', 'type-bug', 'library']
    title = 'socket.getsockname() type mismatch with AF_UNIX on Linux'
    updated_at = <Date 2017-05-02.22:23:04.257>
    user = 'https://github.com/giampaolo'

    bugs.python.org fields:

    activity = <Date 2017-05-02.22:23:04.257>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-05-02.22:23:04.258>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2017-04-29.08:55:10.959>
    creator = 'giampaolo.rodola'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30205
    keywords = []
    message_count = 11.0
    messages = ['292580', '292581', '292702', '292776', '292781', '292806', '292807', '292809', '292810', '292818', '292819']
    nosy_count = 7.0
    nosy_names = ['ronaldoussoren', 'pitrou', 'vstinner', 'giampaolo.rodola', 'christian.heimes', 'ned.deily', 'neologix']
    pr_nums = ['1370', '1404', '1403']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30205'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @giampaolo
    Copy link
    Contributor Author

    >>> import socket
    >>> s = socket.socket(socket.AF_UNIX)
    >>> s.getsockname()
    b''
    >>> s.bind('foo')
    >>> s.getsockname()
    'foo'

    @giampaolo
    Copy link
    Contributor Author

    The change was introduced here:
    b10c71d

    @pitrou
    Copy link
    Member

    pitrou commented May 1, 2017

    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'

    @pitrou pitrou added stdlib Python modules in the Lib dir 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels May 1, 2017
    @pitrou
    Copy link
    Member

    pitrou commented May 2, 2017

    New changeset 495b502 by Antoine Pitrou in branch 'master':
    bpo-30205: Fix getsockname() for unbound AF_UNIX sockets on Linux (bpo-1370)
    495b502

    @giampaolo
    Copy link
    Contributor Author

    Thanks.

    @vstinner
    Copy link
    Member

    vstinner commented May 2, 2017

    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 != ''

    @vstinner
    Copy link
    Member

    vstinner commented May 2, 2017

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

    @pitrou
    Copy link
    Member

    pitrou commented May 2, 2017

    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...

    @vstinner
    Copy link
    Member

    vstinner commented May 2, 2017

    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;                                                           
        }

    @pitrou
    Copy link
    Member

    pitrou commented May 2, 2017

    New changeset 0c2ff08 by Antoine Pitrou in branch '3.6':
    Backport bpo-30205 to 3.6 (bpo-1403)
    0c2ff08

    @pitrou
    Copy link
    Member

    pitrou commented May 2, 2017

    New changeset 0d9d618 by Antoine Pitrou in branch '3.5':
    Backport bpo-30205 to 3.5 (bpo-1404)
    0d9d618

    @pitrou pitrou closed this as completed May 2, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants