Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade libuv to v1.48.0 #600

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions tests/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def _test_getaddrinfo(self, *args, _patch=False, **kwargs):
a1 = patched_getaddrinfo(*args, **kwargs)
else:
a1 = socket.getaddrinfo(*args, **kwargs)
except socket.gaierror as ex:
except (socket.gaierror, UnicodeError) as ex:
err = ex

try:
a2 = self.loop.run_until_complete(
self.loop.getaddrinfo(*args, **kwargs))
except socket.gaierror as ex:
except (socket.gaierror, UnicodeError) as ex:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What input would trigger a UnicodeError?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what @tapple-cisco mentioned with the vulnerability repro, as well as the BPO. A short example with CPython is like:

>>> payload = f'0x{"0"*246}7f000001.example.com'
>>> import socket; socket.getaddrinfo(payload, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/socket.py", line 964, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/encodings/idna.py", line 173, in encode
    raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long
encoding with 'idna' codec failed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is encoding with 'idna' codec failed a context exception?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. .__context__.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's a weird output, let me see

Copy link
Member

@fantix fantix Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's __notes__, this particular note is added in 3.12 (changed from a __context__).

if err is not None:
self.assertEqual(ex.args, err.args)
else:
Expand Down Expand Up @@ -187,6 +187,18 @@ def test_getaddrinfo_20(self):
self._test_getaddrinfo('127.0.0.1', 80, type=socket.SOCK_STREAM,
flags=socket.AI_CANONNAME, _patch=patch)

# https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6
# See also: https://github.com/MagicStack/uvloop/pull/600
def test_getaddrinfo_21(self):
payload = f'0x{"0" * 246}7f000001.example.com'.encode('ascii')
self._test_getaddrinfo(payload, 80)
self._test_getaddrinfo(payload, 80, type=socket.SOCK_STREAM)

def test_getaddrinfo_22(self):
payload = f'0x{"0" * 246}7f000001.example.com'
self._test_getaddrinfo(payload, 80)
self._test_getaddrinfo(payload, 80, type=socket.SOCK_STREAM)

######

def test_getnameinfo_1(self):
Expand Down
17 changes: 9 additions & 8 deletions uvloop/dns.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ cdef class AddrInfoRequest(UVRequest):

if host is None:
chost = NULL
elif host == b'' and sys.platform == 'darwin':
chost = <char*>'localhost'
fantix marked this conversation as resolved.
Show resolved Hide resolved
else:
chost = <char*>host

Expand All @@ -356,13 +358,6 @@ cdef class AddrInfoRequest(UVRequest):
else:
cport = <char*>port

if cport is NULL and chost is NULL:
self.on_done()
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')
ex = socket_gaierror(socket_EAI_NONAME, msg)
callback(ex)
return

memset(&self.hints, 0, sizeof(system.addrinfo))
self.hints.ai_flags = flags
self.hints.ai_family = family
Expand All @@ -382,7 +377,13 @@ cdef class AddrInfoRequest(UVRequest):

if err < 0:
self.on_done()
callback(convert_error(err))
if err == uv.UV_EINVAL:
# Convert UV_EINVAL to EAI_NONAME to match libc behavior
msg = system.gai_strerror(socket_EAI_NONAME).decode('utf-8')
fantix marked this conversation as resolved.
Show resolved Hide resolved
ex = socket_gaierror(socket_EAI_NONAME, msg)
callback(ex)
else:
callback(convert_error(err))


cdef class NameInfoRequest(UVRequest):
Expand Down
2 changes: 1 addition & 1 deletion vendor/libuv
Submodule libuv updated 240 files
Loading