Skip to content

Commit 3453b5c

Browse files
authored
gh-114917: add support for AI_NUMERICSERV in getaddrinfo emulation (#114918)
1 parent b0a4f65 commit 3453b5c

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

Lib/test/test_socket.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,8 +1662,11 @@ def testGetaddrinfo(self):
16621662
# Issue #6697.
16631663
self.assertRaises(UnicodeEncodeError, socket.getaddrinfo, 'localhost', '\uD800')
16641664

1665-
# Issue 17269: test workaround for OS X platform bug segfault
16661665
if hasattr(socket, 'AI_NUMERICSERV'):
1666+
self.assertRaises(socket.gaierror, socket.getaddrinfo, "localhost", "http",
1667+
flags=socket.AI_NUMERICSERV)
1668+
1669+
# Issue 17269: test workaround for OS X platform bug segfault
16671670
try:
16681671
# The arguments here are undefined and the call may succeed
16691672
# or fail. All we care here is that it doesn't segfault.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for AI_NUMERICSERV in getaddrinfo emulation

Modules/addrinfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#undef AI_PASSIVE
7878
#undef AI_CANONNAME
7979
#undef AI_NUMERICHOST
80+
#undef AI_NUMERICSERV
8081
#undef AI_MASK
8182
#undef AI_ALL
8283
#undef AI_V4MAPPED_CFG
@@ -88,8 +89,9 @@
8889
#define AI_PASSIVE 0x00000001 /* get address to use bind() */
8990
#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
9091
#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
92+
#define AI_NUMERICSERV 0x00000008 /* prevent service resolution */
9193
/* valid flags for addrinfo */
92-
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
94+
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
9395

9496
#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
9597
#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */

Modules/getaddrinfo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ getaddrinfo(const char*hostname, const char*servname,
351351
struct servent *sp;
352352
const char *proto;
353353

354+
if (ai->ai_flags & AI_NUMERICSERV) {
355+
ERR(EAI_NONAME);
356+
}
357+
354358
proto = NULL;
355359
switch (pai->ai_socktype) {
356360
case GAI_ANY:

0 commit comments

Comments
 (0)