-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
Comments
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. |
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. |
The crash occurs in OS X's libsystem_info on 10.8. Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 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. |
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. |
That's interesting... this also crashes:
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? |
I've filed radar #13271126 for this in Apple's tracker. |
On win7, the original example and '0' version give |
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. |
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) |
New changeset f4981d8eb401 by Ronald Oussoren in branch '2.7': New changeset 3c4a5dc29417 by Ronald Oussoren in branch '3.3': New changeset 24ffb0148729 by Ronald Oussoren in branch 'default': |
Hi, I think this broke the tiger buildbot: http://buildbot.python.org/all/builders/x86%20Tiger%203.x/builds/6368/steps/test/logs/stdio |
That sucks. A patch should be easy, but I probably won't get around to that until sunday. |
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. |
New changeset 4d1e4bc6c5b5 by Ronald Oussoren in branch '2.7': New changeset ef103e7e7af2 by Ronald Oussoren in branch '3.3': New changeset 062f1985a5b7 by Ronald Oussoren in branch 'default': |
The buildbot seems to be happy right now (at least as far as getaddrinfo is concerned). |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: