]> granicus.if.org Git - python/commitdiff
Issue #1027206: getnameinfo is now restricted to numeric addresses as input.
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 25 Aug 2010 07:38:15 +0000 (07:38 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 25 Aug 2010 07:38:15 +0000 (07:38 +0000)
Lib/test/test_socket.py
Misc/NEWS
Modules/socketmodule.c

index 60e5bf7e2c414f5057424aec258372a101ba1d71..5a8aa5a905998c39468f522b2c3d4b48d47791d9 100644 (file)
@@ -637,6 +637,10 @@ class GeneralModuleTests(unittest.TestCase):
                                flags=socket.AI_PASSIVE)
         self.assertEqual(a, b)
 
+    def test_getnameinfo(self):
+        # only IP addresses are allowed
+        self.assertRaises(socket.error, socket.getnameinfo, ('mail.python.org',0), 0)
+
     def test_idna(self):
         # these should all be successful
         socket.gethostbyname('испытание.python.org')
index 1cb67ccf478d5f3d985a4e623e620f795d6be654..7aebbe73fa2b2f1d0062ad41dfc1847b90b35194 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -70,7 +70,8 @@ Extensions
 ----------
 
 - Issue #1027206: Support IDNA in gethostbyname, gethostbyname_ex, 
-  getaddrinfo and gethostbyaddr.
+  getaddrinfo and gethostbyaddr. getnameinfo is now restricted to numeric
+  addresses as input.
 
 - Issue #9214: Set operations on a KeysView or ItemsView in collections
   now correctly return a set.  (Patch by Eli Bendersky.)
index 709c85e213eaefac925c59d44b1178440e23653c..8c743d87f5e607f251e11abb5fe19c99da52e753 100644 (file)
@@ -3969,6 +3969,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
     memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_DGRAM;     /* make numeric port happy */
+    hints.ai_flags = AI_NUMERICHOST;    /* don't do any name resolution */
     Py_BEGIN_ALLOW_THREADS
     ACQUIRE_GETADDRINFO_LOCK
     error = getaddrinfo(hostp, pbuf, &hints, &res);