pkgcore / pkgcheck

pkgcore-based QA utility for ebuild repos
https://pkgcore.github.io/pkgcheck
BSD 3-Clause "New" or "Revised" License
35 stars 29 forks source link

Fix crash when performing a `scan--net --timeout 0` call to a ftp site #678

Closed antecrescent closed 4 months ago

antecrescent commented 5 months ago

Problem

Pkgcheck's underlying ftplib raises an unintended ValueError, before establishing a connection to a ftp site, when --timeout is set to 0.

Fix

Instead of 0, pkgcheck should pass None here. Legal timeout values are described here: https://docs.python.org/3/library/socket.html#socket.socket.settimeout Since we now want to pass None regardless of the protocol if timeout is 0, I moved the value-handling part to NetAddon, which serves it both to the Session constructor, as well as to NetworkCheck and thus to _ftp_check.

I also modified test_custom_timeout to assert that NetAddon handles all non-negative inputs correctly.

I'm looking forward to hearing your feedback!

How to Reproduce

With ::gentoo at checkout 127160ac611d39cc6bb2ca21fcf99a086fe2b176:

$ equery m -U app-admin/chrootuid
 * app-admin/chrootuid [gentoo]
Homepage:    ftp://ftp.porcupine.org/pub/security/index.html

pkgcheck scan --net -c HomepageUrlCheck --timeout 0 app-admin/chrootuid should not fail but it does:

pkgcheck scan: error: Traceback (most recent call last):
  File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.11/site-packages/pkgcheck/checks/network.py", line 168, in _ftp_check
    urllib.request.urlopen(url, timeout=self.timeout)
  File "/usr/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 1565, in ftp_open
    fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 1585, in connect_ftp
    return ftpwrapper(user, passwd, host, port, dirs, timeout,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 2413, in __init__
    self.init()
  File "/usr/lib/python3.11/urllib/request.py", line 2422, in init
    self.ftp.connect(self.host, self.port, self.timeout)
  File "/usr/lib/python3.11/ftplib.py", line 154, in connect
    raise ValueError('Non-blocking socket (timeout=0) is not supported')
ValueError: Non-blocking socket (timeout=0) is not supported
antecrescent commented 4 months ago

The dependency installation for the previous macOS build failed, because there's no arm64 wheel available on PyPI for >=tree-sitter-bash-0.21.0.

arthurzam commented 4 months ago

The dependency installation for the previous macOS build failed, because there's no arm64 wheel available on PyPI for >=tree-sitter-bash-0.21.0.

let's ignore that. I'll make it not failing issue. The next release by tree-sitter-bash will have sdist + macos wheels (link) so it will fix itself in future.

antecrescent commented 4 months ago

My pleasure!