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

getaddrinfo segfaults on OS X when provided with invalid arguments combinations #61471

Closed
tibbe mannequin opened this issue Feb 21, 2013 · 15 comments
Closed

getaddrinfo segfaults on OS X when provided with invalid arguments combinations #61471

tibbe mannequin opened this issue Feb 21, 2013 · 15 comments
Assignees
Labels
OS-mac release-blocker stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@tibbe
Copy link
Mannequin

tibbe mannequin commented Feb 21, 2013

BPO 17269
Nosy @birkenfeld, @terryjreedy, @ronaldoussoren, @vstinner, @larryhastings, @benjaminp, @ned-deily, @skrah
Files
  • issue17269.txt
  • issue17269-with-tests.txt
  • 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 = 'https://github.com/ronaldoussoren'
    closed_at = <Date 2013-06-11.16:01:58.510>
    created_at = <Date 2013-02-21.23:31:53.455>
    labels = ['OS-mac', 'library', 'type-crash', 'release-blocker']
    title = 'getaddrinfo segfaults on OS X when provided with invalid arguments combinations'
    updated_at = <Date 2013-06-11.16:01:58.509>
    user = 'https://bugs.python.org/tibbe'

    bugs.python.org fields:

    activity = <Date 2013-06-11.16:01:58.509>
    actor = 'ronaldoussoren'
    assignee = 'ronaldoussoren'
    closed = True
    closed_date = <Date 2013-06-11.16:01:58.510>
    closer = 'ronaldoussoren'
    components = ['Library (Lib)', 'macOS']
    creation = <Date 2013-02-21.23:31:53.455>
    creator = 'tibbe'
    dependencies = []
    files = ['29160', '29991']
    hgrepos = []
    issue_num = 17269
    keywords = ['patch', 'needs review']
    message_count = 15.0
    messages = ['182615', '182617', '182619', '182652', '182654', '182655', '182695', '183116', '187633', '189907', '190332', '190348', '190598', '190893', '190973']
    nosy_count = 10.0
    nosy_names = ['georg.brandl', 'terry.reedy', 'ronaldoussoren', 'vstinner', 'larry', 'benjamin.peterson', 'ned.deily', 'skrah', 'python-dev', 'tibbe']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'needs patch'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue17269'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @tibbe
    Copy link
    Mannequin Author

    tibbe mannequin commented Feb 21, 2013

    The following call to getaddrinfo makes Python segfault:

    $ python
    Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
    [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> socket.getaddrinfo("localhost", None, 0, 0, 0, socket.AI_NUMERICSERV)
    Segmentation fault: 11

    The combination of no port (None) and socket.AI_NUMERICSERV makes no sense (I used it by mistake) but we probably don't want to segfault anyway.

    @tibbe tibbe mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Feb 21, 2013
    @vstinner
    Copy link
    Member

    Linux manual page: "If AI_NUMERICSERV is specified in hints.ai_flags and service is not NULL, then service must point to a string containing a numeric port number."

    So it looks like None is accepted on Linux. I checked: the example doesn't crash.

    @ned-deily
    Copy link
    Member

    The crash occurs in OS X's libsystem_info on 10.8.

    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
    0 libsystem_info.dylib 0x00007fff86bacd9e mdns_addrinfo + 299
    1 libsystem_info.dylib 0x00007fff86badae2 search_addrinfo + 152
    2 libsystem_info.dylib 0x00007fff86b97f6d si_addrinfo + 1641
    3 libsystem_info.dylib 0x00007fff86b9785c getaddrinfo + 171
    4 _socket.so 0x0000000100516524 socket_getaddrinfo + 500

    It's also reproducible back on OS X 10.6 crashing there in libSystem. (It looks like earlier versions of OS X don't support the AI_NUMERICSERV flag.) So it would appear to be a long-standing OS X bug. Possible actions: open an Apple incident and patch socket.getaddrinfo to catch this case.

    @ronaldoussoren
    Copy link
    Contributor

    Looks like a bug in libSystem, see mdns_addrinfo in <http://www.opensource.apple.com/source/Libinfo/Libinfo-406.17/lookup.subproj/mdns_module.c\>. Its handling of AI_NUMERICSERV doesn't match that of si_getaddrinfo.c at the same location.

    I'll file a bug with Apple, anyone running into this problem migh want to do so as well (Apple's tracker is more or less a popularity contest, the more an issue is report, the more likely it is to get fixed).

    I'm in favor of working around this bug on OSX by settings the servname to "0" when AI_NUMERICSERVICE is set and the passed in service name is None. I\m working on a patch.

    @ronaldoussoren
    Copy link
    Contributor

    That's interesting... this also crashes:

    >> socket.getaddrinfo("localhost", "0", 0, 0, 0, socket.AI_NUMERICSERV)

    While using another port number does not.

    The attached patches for the default branch fixes the issue for me (on OSX 10.8).

    The same approach should also work with 2.7 (but the patch likely won't apply cleanly due to the use of TABs for indents in 2.7 and spaces in 3.x).

    Open issue: should there be a testcase for this problem?

    @ronaldoussoren
    Copy link
    Contributor

    I've filed radar #13271126 for this in Apple's tracker.

    @terryjreedy
    Copy link
    Member

    On win7, the original example and '0' version give
    [(23, 0, 0, '', ('::1', 0, 0, 0)), (2, 0, 0, '', ('127.0.0.1', 0))]
    I think a testcase would be good.

    @ronaldoussoren
    Copy link
    Contributor

    My bug submission at Apple was closed as a duplicate of radar 13058317.

    Given the state of testing of getaddrinfo a testcase will be easier than expected, just pasting the call in this bugreport into the right testcase will match the style of most other checks in that testcase.

    @ronaldoussoren
    Copy link
    Contributor

    I've updated the patch: it now contains a testcase (although the getaddrinfo tests are stretching the definition of the word, the new test only checks that the function doesn't crash)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 24, 2013

    New changeset f4981d8eb401 by Ronald Oussoren in branch '2.7':
    Issue bpo-17269: Workaround for a platform bug in getaddrinfo on OSX
    http://hg.python.org/cpython/rev/f4981d8eb401

    New changeset 3c4a5dc29417 by Ronald Oussoren in branch '3.3':
    Issue bpo-17269: Workaround for a platform bug in getaddrinfo on OSX
    http://hg.python.org/cpython/rev/3c4a5dc29417

    New changeset 24ffb0148729 by Ronald Oussoren in branch 'default':
    (3.3->default) Issue bpo-17269: Workaround for a platform bug in getaddrinfo on OSX
    http://hg.python.org/cpython/rev/24ffb0148729

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented May 29, 2013

    @ronaldoussoren
    Copy link
    Contributor

    That sucks. A patch should be easy, but I probably won't get around to that until sunday.

    @ronaldoussoren
    Copy link
    Contributor

    I've tested a patch for the 2.7 branch on a 10.5 machine (which also failed to build without the patch), and will commit once I've finished running the testsuite on the 3.3 branch as well.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 10, 2013

    New changeset 4d1e4bc6c5b5 by Ronald Oussoren in branch '2.7':
    Ensure that the fix for bpo-17269 also works on OSX 10.4
    http://hg.python.org/cpython/rev/4d1e4bc6c5b5

    New changeset ef103e7e7af2 by Ronald Oussoren in branch '3.3':
    Ensure that the fix for bpo-17269 also works on OSX 10.4
    http://hg.python.org/cpython/rev/ef103e7e7af2

    New changeset 062f1985a5b7 by Ronald Oussoren in branch 'default':
    (3.3->default) Ensure that the fix for bpo-17269 also works on OSX 10.4
    http://hg.python.org/cpython/rev/062f1985a5b7

    @ronaldoussoren
    Copy link
    Contributor

    The buildbot seems to be happy right now (at least as far as getaddrinfo is concerned).

    @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
    OS-mac release-blocker stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants