Skip to content

Commit de718e4

Browse files
committed
Only accept numeric address in getnameinfo
1 parent 29308e7 commit de718e4

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/core/IronPython.Modules/_socket.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ public static object getnameinfo(CodeContext/*!*/ context, [NotNone] PythonTuple
11731173
// Host
11741174
IList<IPAddress> addrs;
11751175
try {
1176-
addrs = HostToAddresses(context, host, AddressFamily.InterNetwork);
1176+
addrs = HostToAddresses(context, host, AddressFamily.InterNetwork, getHostEntry: false);
11771177
} catch (IndexOutOfRangeException) {
11781178
throw MakeGaiException(context, EAI_NODATA);
11791179
}
@@ -2002,7 +2002,7 @@ private static IPAddress HostToAddress(CodeContext/*!*/ context, string host, Ad
20022002
/// not the same as the specified family. gaierror is also raised if the hostname cannot be
20032003
/// converted to an IP address (e.g. through a name lookup failure).
20042004
/// </summary>
2005-
private static IPAddress[] HostToAddresses(CodeContext/*!*/ context, string host, AddressFamily family) {
2005+
private static IPAddress[] HostToAddresses(CodeContext/*!*/ context, string host, AddressFamily family, bool getHostEntry = true) {
20062006
host = ConvertSpecialAddresses(host);
20072007
try {
20082008
bool numeric = true;
@@ -2022,6 +2022,9 @@ private static IPAddress[] HostToAddresses(CodeContext/*!*/ context, string host
20222022
}
20232023
// Incorrect family will raise EAI_NODATA exception below
20242024
} else {
2025+
if (!getHostEntry) {
2026+
throw MakeGaiException(context, EAI_NONAME);
2027+
}
20252028
IPHostEntry hostEntry = Dns.GetHostEntry(host);
20262029
List<IPAddress> addrs = new List<IPAddress>();
20272030
foreach (IPAddress ip in hostEntry.AddressList) {
@@ -2032,7 +2035,7 @@ private static IPAddress[] HostToAddresses(CodeContext/*!*/ context, string host
20322035
if (addrs.Count > 0) return addrs.ToArray();
20332036
}
20342037
throw MakeGaiException(context, EAI_NODATA);
2035-
} catch (SocketException ex) {
2038+
} catch (SocketException ex) {
20362039
throw MakeGaiException(context, ex);
20372040
}
20382041
}

src/core/IronPython/Runtime/Operations/StringOps.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ public static bool isalpha([NotNone] this string self) {
623623
return true;
624624
}
625625

626+
// new in Python 3.7
626627
public static bool isascii([NotNone] this string self) {
627628
foreach (char c in self) {
628629
if (c > 0x7f) return false;

tests/suite/modules/network_related/test__socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ def test_getnameinfo(self):
352352
host, service = _socket.getnameinfo( ("127.0.0.1", 80), 0)
353353
self.assertEqual(service, "http")
354354
#IP gives a TypeError
355-
#self.assertRaises(SystemError, _socket.getnameinfo, ("127.0.0.1"), 8)
356-
#self.assertRaises(SystemError, _socket.getnameinfo, (321), 8)
355+
self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1"), 8)
356+
self.assertRaises(TypeError, _socket.getnameinfo, (321), 8)
357357
self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1"), '0')
358358
self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1", 80, 0, 0, 0), 8)
359359
self.assertRaises(_socket.gaierror, _socket.getnameinfo, ('no such host will ever exist', 80), 8)

tests/suite/test_socket_stdlib.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ def load_tests(loader, standard_tests, pattern):
4141
failing_tests += [
4242
test.test_socket.NonBlockingTCPTests('testRecv'), # TODO: figure out
4343
]
44-
if not is_mono:
45-
failing_tests += [
46-
test.test_socket.GeneralModuleTests('test_getnameinfo'), # https://github.com/IronLanguages/ironpython3/issues/1222
47-
]
4844
if is_linux:
4945
failing_tests += [
5046
test.test_socket.GeneralModuleTests('test_idna'), # TODO: figure out

0 commit comments

Comments
 (0)