]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17269: Workaround for a platform bug in getaddrinfo on OSX
authorRonald Oussoren <ronaldoussoren@mac.com>
Fri, 24 May 2013 11:47:37 +0000 (13:47 +0200)
committerRonald Oussoren <ronaldoussoren@mac.com>
Fri, 24 May 2013 11:47:37 +0000 (13:47 +0200)
Without this patch socket.getaddrinfo crashed when called
with some unusual argument combinations.

Lib/test/test_socket.py
Misc/NEWS
Modules/socketmodule.c

index d20e37bff6f7024787449cb0fed104590d5beb92..546a10d23a7f733cde417539bcc10ab8626a9b2c 100644 (file)
@@ -1166,6 +1166,9 @@ class GeneralModuleTests(unittest.TestCase):
         # Issue #6697.
         self.assertRaises(UnicodeEncodeError, socket.getaddrinfo, 'localhost', '\uD800')
 
+        # Issue 17269
+        socket.getaddrinfo("localhost", None, 0, 0, 0, socket.AI_NUMERICSERV)
+
     def test_getnameinfo(self):
         # only IP addresses are allowed
         self.assertRaises(socket.error, socket.getnameinfo, ('mail.python.org',0), 0)
index a4e7101e017f028e4b759f30594ea39e08452b90..125b153ee70fe15a6e837c3c707196e85bfec979 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Library
 
 - Issue #17968: Fix memory leak in os.listxattr().
 
+- Issue #17269: Workaround for socket.getaddrinfo crash on MacOS X
+  with port None or "0" and flags AI_NUMERICSERV.
+
 IDLE
 ----
 
index 92000024af38a3b294012cf046abded0fac10c80..679143cc9363b09f707919ad3373a7ef312b8b0c 100644 (file)
@@ -5041,6 +5041,15 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
         PyErr_SetString(PyExc_OSError, "Int or String expected");
         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));
     hints.ai_family = family;
     hints.ai_socktype = socktype;