Skip to content

Commit 4f94fd4

Browse files
authored
Merge branch 'master' into resolve-broadcast-hostname
2 parents cc33fbf + 7777852 commit 4f94fd4

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

tests/test_dns.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def _test_getaddrinfo(self, *args, _patch=False, **kwargs):
3131
a1 = patched_getaddrinfo(*args, **kwargs)
3232
else:
3333
a1 = socket.getaddrinfo(*args, **kwargs)
34-
except socket.gaierror as ex:
34+
except (socket.gaierror, UnicodeError) as ex:
3535
err = ex
3636

3737
try:
3838
a2 = self.loop.run_until_complete(
3939
self.loop.getaddrinfo(*args, **kwargs))
40-
except socket.gaierror as ex:
40+
except (socket.gaierror, UnicodeError) as ex:
4141
if err is not None:
4242
self.assertEqual(ex.args, err.args)
4343
else:
@@ -187,6 +187,18 @@ def test_getaddrinfo_20(self):
187187
self._test_getaddrinfo('127.0.0.1', 80, type=socket.SOCK_STREAM,
188188
flags=socket.AI_CANONNAME, _patch=patch)
189189

190+
# https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6
191+
# See also: https://github.com/MagicStack/uvloop/pull/600
192+
def test_getaddrinfo_21(self):
193+
payload = f'0x{"0" * 246}7f000001.example.com'.encode('ascii')
194+
self._test_getaddrinfo(payload, 80)
195+
self._test_getaddrinfo(payload, 80, type=socket.SOCK_STREAM)
196+
197+
def test_getaddrinfo_22(self):
198+
payload = f'0x{"0" * 246}7f000001.example.com'
199+
self._test_getaddrinfo(payload, 80)
200+
self._test_getaddrinfo(payload, 80, type=socket.SOCK_STREAM)
201+
190202
######
191203

192204
def test_getnameinfo_1(self):

tests/test_tcp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ def test_create_server_4(self):
248248
addr = sock.getsockname()
249249

250250
with self.assertRaisesRegex(OSError,
251-
r"error while attempting.*\('127.*: "
252-
r"address( already)? in use"):
251+
r"error while attempting.*\('127.*:"
252+
r"( \[errno \d+\])? address"
253+
r"( already)? in use"):
253254

254255
self.loop.run_until_complete(
255256
self.loop.create_server(object, *addr))

uvloop/dns.pyx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ cdef class AddrInfoRequest(UVRequest):
352352

353353
if host is None:
354354
chost = NULL
355+
elif host == b'' and sys.platform == 'darwin':
356+
# It seems `getaddrinfo("", ...)` on macOS is equivalent to
357+
# `getaddrinfo("localhost", ...)`. This is inconsistent with
358+
# libuv 1.48 which treats empty nodename as EINVAL.
359+
chost = <char*>'localhost'
355360
else:
356361
chost = <char*>host
357362

@@ -360,13 +365,6 @@ cdef class AddrInfoRequest(UVRequest):
360365
else:
361366
cport = <char*>port
362367

363-
if cport is NULL and chost is NULL:
364-
self.on_done()
365-
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')
366-
ex = socket_gaierror(socket_EAI_NONAME, msg)
367-
callback(ex)
368-
return
369-
370368
memset(&self.hints, 0, sizeof(system.addrinfo))
371369
self.hints.ai_flags = flags
372370
self.hints.ai_family = family
@@ -386,7 +384,17 @@ cdef class AddrInfoRequest(UVRequest):
386384

387385
if err < 0:
388386
self.on_done()
389-
callback(convert_error(err))
387+
try:
388+
if err == uv.UV_EINVAL:
389+
# Convert UV_EINVAL to EAI_NONAME to match libc behavior
390+
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')
391+
ex = socket_gaierror(socket_EAI_NONAME, msg)
392+
else:
393+
ex = convert_error(err)
394+
except Exception as ex:
395+
callback(ex)
396+
else:
397+
callback(ex)
390398

391399

392400
cdef class NameInfoRequest(UVRequest):

vendor/libuv

Submodule libuv updated 240 files

0 commit comments

Comments
 (0)