From 16c52a337644e0223c2004168551ff2ba7884cb7 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Fri, 24 May 2013 13:45:27 +0200 Subject: [PATCH] Issue #17269: Workaround for a platform bug in getaddrinfo on OSX Without this patch socket.getaddrinfo crashed when called with some unusual argument combinations. --- Lib/test/test_socket.py | 2 ++ Misc/NEWS | 5 ++++- Modules/socketmodule.c | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 111e55394a62..3b112e68384a 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -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. diff --git a/Misc/NEWS b/Misc/NEWS index 9c472ddbf9f9..8fdc8810a80f 100644 --- 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, diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index bdc055dd384f..238c849b8459 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -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; -- 2.47.3