-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apport_python_hook: Fix crash if os.getcwd() fails
Example `getcwd.py`: ```python import os import tempfile tempdir = tempfile.mkdtemp() os.chdir(tempdir) os.rmdir(tempdir) os.getcwd() ``` Apport's Python hook will fail: ``` $ python3 getcwd.py Traceback (most recent call last): File "getcwd.py", line 7, in <module> os.getcwd() FileNotFoundError: [Errno 2] No such file or directory Error in sys.excepthook: Traceback (most recent call last): File "apport_python_hook.py", line 71, in apport_excepthook binary = os.path.realpath(os.path.join(os.getcwd(), sys.argv[0])) FileNotFoundError: [Errno 2] No such file or directory Original exception was: Traceback (most recent call last): File "getcwd.py", line 7, in <module> os.getcwd() FileNotFoundError: [Errno 2] No such file or directory ``` Since the program can change the current directory and mutate `sys.argv` (and also change `/proc/self/cmdline` using the `setproctitle` Python module), there is no alternative to record the binary name during starup when registering the Python hook. Bug: https://launchpad.net/bugs/1977954 Signed-off-by: Benjamin Drung <[email protected]>
- Loading branch information
Showing
2 changed files
with
69 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters