Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove /usr/bin from sys.path to avoid accidentally importing garbage
See https://bugzilla.redhat.com/show_bug.cgi?id=2057340 and benjaminp/six#359 dnf should never import Python modules from /usr/bin but users can have files in there that look like Python modules and Python will try to import them and fail. Consider a tool that is *not* written in Python and is called "copy.pyc". Naturally, it resides in /usr/bin/copy.pyc and dnf fails: Traceback (most recent call last): File "/usr/bin/dnf", line 57, in <module> from dnf.cli import main File "/usr/lib/python3.10/site-packages/dnf/__init__.py", line 30, in <module> import dnf.base File "/usr/lib/python3.10/site-packages/dnf/base.py", line 31, in <module> from copy import deepcopy ImportError: bad magic number in 'copy': b'...' Similarly, a tool actually written in Python, called "copy.py" might as well own /usr/bin/copy.py and dnf fails as well: Traceback (most recent call last): File "/usr/bin/dnf", line 57, in <module> from dnf.cli import main File "/usr/lib/python3.10/site-packages/dnf/__init__.py", line 30, in <module> import dnf.base File "/usr/lib/python3.10/site-packages/dnf/base.py", line 31, in <module> from copy import deepcopy ImportError: cannot import name 'deepcopy' from 'copy' (/usr/bin/copy.py) Either problem can happen for a variety of names. We better not let that happen. A more general solution that would prevent Python doing this entirely does not exists yet, see https://discuss.python.org/t/4235 Hence, proposing this to dnf, which is a critical piece of the system.
- Loading branch information