Skip to content

Commit

Permalink
Merge branch 'master' into restore-signals
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix authored Aug 15, 2024
2 parents 118f595 + deb2cf9 commit 2caba9a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest]
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ To build uvloop, you'll need Python 3.8 or greater:

.. code::
$ python3.7 -m venv uvloop-dev
$ python3 -m venv uvloop-dev
$ source uvloop-dev/bin/activate
3. Install development dependencies:
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ def build_libuv(self):
cmd,
cwd=LIBUV_BUILD_DIR, env=env, check=True)

j_flag = '-j{}'.format(os.cpu_count() or 1)
try:
njobs = len(os.sched_getaffinity(0))
except AttributeError:
njobs = os.cpu_count()
j_flag = '-j{}'.format(njobs or 1)
c_flag = "CFLAGS={}".format(env['CFLAGS'])
subprocess.run(
['make', j_flag, c_flag],
Expand Down
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:
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
5 changes: 3 additions & 2 deletions tests/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ def test_create_server_4(self):
addr = sock.getsockname()

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

self.loop.run_until_complete(
self.loop.create_server(object, *addr))
Expand Down
24 changes: 16 additions & 8 deletions uvloop/dns.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ cdef class AddrInfoRequest(UVRequest):

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

Expand All @@ -356,13 +361,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 +380,17 @@ cdef class AddrInfoRequest(UVRequest):

if err < 0:
self.on_done()
callback(convert_error(err))
try:
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')
ex = socket_gaierror(socket_EAI_NONAME, msg)
else:
ex = convert_error(err)
except Exception as ex:
callback(ex)
else:
callback(ex)


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

0 comments on commit 2caba9a

Please sign in to comment.