]> 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:45:27 +0000 (13:45 +0200)
committerRonald Oussoren <ronaldoussoren@mac.com>
Fri, 24 May 2013 11:45:27 +0000 (13:45 +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 111e55394a62b3721f2d97fb59d3c90b5a611f06..3b112e68384ac115e2b1a85c613442ea33afd961 100644 (file)
@@ -665,6 +665,8 @@ class GeneralModuleTests(unittest.TestCase):
         socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                            socket.AI_PASSIVE)
 
+        # Issue 17269
+        socket.getaddrinfo("localhost", None, 0, 0, 0, socket.AI_NUMERICSERV)
 
     def check_sendall_interrupted(self, with_timeout):
         # socketpair() is not stricly required, but it makes things easier.
index 9c472ddbf9f999c33741b6182c25d2bb9971df69..8fdc8810a80f321fc6ca9b8f324acd77f20e9175 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,9 @@ Library
 
 - 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
 ----
 
@@ -51,7 +54,7 @@ What's New in Python 2.7.5?
 Core and Builtins
 -----------------
 
-- Issue #15535: Fixed regression in the pickling of named tuples by 
+- Issue #15535: Fixed regression in the pickling of named tuples by
   removing the __dict__ property introduced in 2.7.4.
 
 - Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,
index bdc055dd384f60c40019a02d999fe93163786971..238c849b8459e45bc01a136ff0ac59d8a6d2da80 100644 (file)
@@ -4179,6 +4179,15 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
                         "getaddrinfo() argument 2 must be integer or string");
         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;