Skip to content

Commit 7777852

Browse files
niklasr22fantix
andauthored
Upgrade libuv to v1.48.0 (#600)
* Fix for libuv 1.48 * Fix for macOS (resolve empty host string as "localhost") * Add test --------- Co-authored-by: Fantix King <fantix.king@gmail.com>
1 parent 62f9239 commit 7777852

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

Diff for: tests/test_dns.py

+14-2
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):

Diff for: uvloop/dns.pyx

+16-8
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ cdef class AddrInfoRequest(UVRequest):
348348

349349
if host is None:
350350
chost = NULL
351+
elif host == b'' and sys.platform == 'darwin':
352+
# It seems `getaddrinfo("", ...)` on macOS is equivalent to
353+
# `getaddrinfo("localhost", ...)`. This is inconsistent with
354+
# libuv 1.48 which treats empty nodename as EINVAL.
355+
chost = <char*>'localhost'
351356
else:
352357
chost = <char*>host
353358

@@ -356,13 +361,6 @@ cdef class AddrInfoRequest(UVRequest):
356361
else:
357362
cport = <char*>port
358363

359-
if cport is NULL and chost is NULL:
360-
self.on_done()
361-
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')
362-
ex = socket_gaierror(socket_EAI_NONAME, msg)
363-
callback(ex)
364-
return
365-
366364
memset(&self.hints, 0, sizeof(system.addrinfo))
367365
self.hints.ai_flags = flags
368366
self.hints.ai_family = family
@@ -382,7 +380,17 @@ cdef class AddrInfoRequest(UVRequest):
382380

383381
if err < 0:
384382
self.on_done()
385-
callback(convert_error(err))
383+
try:
384+
if err == uv.UV_EINVAL:
385+
# Convert UV_EINVAL to EAI_NONAME to match libc behavior
386+
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')
387+
ex = socket_gaierror(socket_EAI_NONAME, msg)
388+
else:
389+
ex = convert_error(err)
390+
except Exception as ex:
391+
callback(ex)
392+
else:
393+
callback(ex)
386394

387395

388396
cdef class NameInfoRequest(UVRequest):

Diff for: vendor/libuv

Submodule libuv updated 240 files

0 commit comments

Comments
 (0)