https://github.com/python/cpython/commit/3453b5c1d652a0424a333332b576f9b878424061
commit: 3453b5c1d652a0424a333332b576f9b878424061
branch: main
author: Max Bachmann <kont...@maxbachmann.de>
committer: vstinner <vstin...@python.org>
date: 2025-03-18T11:26:51+01:00
summary:

gh-114917: add support for AI_NUMERICSERV in getaddrinfo emulation (#114918)

files:
A Misc/NEWS.d/next/Library/2024-02-02-15-26-48.gh-issue-114917.sf0GuO.rst
M Lib/test/test_socket.py
M Modules/addrinfo.h
M Modules/getaddrinfo.c

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index fc6e8593ae30bb..6572032c1d14bd 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1662,8 +1662,11 @@ def testGetaddrinfo(self):
         # Issue #6697.
         self.assertRaises(UnicodeEncodeError, socket.getaddrinfo, 'localhost', 
'\uD800')
 
-        # Issue 17269: test workaround for OS X platform bug segfault
         if hasattr(socket, 'AI_NUMERICSERV'):
+            self.assertRaises(socket.gaierror, socket.getaddrinfo, 
"localhost", "http",
+                              flags=socket.AI_NUMERICSERV)
+
+            # Issue 17269: test workaround for OS X platform bug segfault
             try:
                 # The arguments here are undefined and the call may succeed
                 # or fail.  All we care here is that it doesn't segfault.
diff --git 
a/Misc/NEWS.d/next/Library/2024-02-02-15-26-48.gh-issue-114917.sf0GuO.rst 
b/Misc/NEWS.d/next/Library/2024-02-02-15-26-48.gh-issue-114917.sf0GuO.rst
new file mode 100644
index 00000000000000..02aab3fd07e108
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-02-02-15-26-48.gh-issue-114917.sf0GuO.rst
@@ -0,0 +1 @@
+Add support for AI_NUMERICSERV in getaddrinfo emulation
diff --git a/Modules/addrinfo.h b/Modules/addrinfo.h
index 66e5a795f86f19..8c2cb3b4f3e727 100644
--- a/Modules/addrinfo.h
+++ b/Modules/addrinfo.h
@@ -77,6 +77,7 @@
 #undef AI_PASSIVE
 #undef AI_CANONNAME
 #undef AI_NUMERICHOST
+#undef AI_NUMERICSERV
 #undef AI_MASK
 #undef AI_ALL
 #undef AI_V4MAPPED_CFG
@@ -88,8 +89,9 @@
 #define AI_PASSIVE      0x00000001 /* get address to use bind() */
 #define AI_CANONNAME    0x00000002 /* fill ai_canonname */
 #define AI_NUMERICHOST  0x00000004 /* prevent name resolution */
+#define AI_NUMERICSERV  0x00000008 /* prevent service resolution */
 /* valid flags for addrinfo */
-#define AI_MASK         (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
+#define AI_MASK         (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | 
AI_NUMERICSERV)
 
 #define AI_ALL          0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) 
*/
 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c
index 7a178671fe6e87..5219330d0f61e8 100644
--- a/Modules/getaddrinfo.c
+++ b/Modules/getaddrinfo.c
@@ -351,6 +351,10 @@ getaddrinfo(const char*hostname, const char*servname,
             struct servent *sp;
             const char *proto;
 
+            if (ai->ai_flags & AI_NUMERICSERV) {
+                ERR(EAI_NONAME);
+            }
+
             proto = NULL;
             switch (pai->ai_socktype) {
             case GAI_ANY:

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to