Commit 16c52a33 authored by Ronald Oussoren's avatar Ronald Oussoren

Issue #17269: Workaround for a platform bug in getaddrinfo on OSX

Without this patch socket.getaddrinfo crashed when called
with some unusual argument combinations.
parent 668b0058
...@@ -665,6 +665,8 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -665,6 +665,8 @@ class GeneralModuleTests(unittest.TestCase):
socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
socket.AI_PASSIVE) socket.AI_PASSIVE)
# Issue 17269
socket.getaddrinfo("localhost", None, 0, 0, 0, socket.AI_NUMERICSERV)
def check_sendall_interrupted(self, with_timeout): def check_sendall_interrupted(self, with_timeout):
# socketpair() is not stricly required, but it makes things easier. # socketpair() is not stricly required, but it makes things easier.
......
...@@ -23,6 +23,9 @@ Library ...@@ -23,6 +23,9 @@ Library
- Fix typos in the multiprocessing module. - Fix typos in the multiprocessing module.
- Issue #17269: Workaround for socket.getaddrinfo crash on MacOS X
with port None or "0" and flags AI_NUMERICSERV.
IDLE IDLE
---- ----
......
...@@ -4179,6 +4179,15 @@ socket_getaddrinfo(PyObject *self, PyObject *args) ...@@ -4179,6 +4179,15 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
"getaddrinfo() argument 2 must be integer or string"); "getaddrinfo() argument 2 must be integer or string");
goto err; goto err;
} }
#ifdef __APPLE__
if ((flags & AI_NUMERICSERV) && (pptr == NULL || (pptr[0] == '0' && pptr[1] == 0))) {
/* On OSX upto at least OSX 10.8 getaddrinfo crashes
* if AI_NUMERICSERV is set and the servname is NULL or "0".
* This workaround avoids a segfault in libsystem.
*/
pptr = "00";
}
#endif
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = family; hints.ai_family = family;
hints.ai_socktype = socktype; hints.ai_socktype = socktype;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment