[Bug 1977954] Re: apport_python_hook: Crashes if os.getcwd() throws FileNotFoundError

Benjamin Drung 1977954 at bugs.launchpad.net
Mon Jun 27 16:47:15 UTC 2022


** Description changed:

- Example code:
+ Test Case
+ ---------
+ 
+ 1. Create /tmp/getcwd.py with following content:
  ```
  #!/usr/bin/python3
  
  import os
  import tempfile
  
  tempdir = tempfile.mkdtemp()
  os.chdir(tempdir)
  os.rmdir(tempdir)
  os.getcwd()
  ```
+ 2. Make it executable and execute it.
  
- Once executed:
+ It should produce following output:
  
  ```
- $ /tmp/getcwd.py
- Traceback (most recent call last):
-   File "/tmp/getcwd.py", line 9, in <module>
-     os.getcwd()
- FileNotFoundError: [Errno 2] No such file or directory
- Error in sys.excepthook:
- Traceback (most recent call last):
-   File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 76, 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 "/tmp/getcwd.py", line 9, in <module>
      os.getcwd()
  FileNotFoundError: [Errno 2] No such file or directory
  ```
  
+ instead of:
+ 
+ ```
+ $ /tmp/getcwd.py
+ Traceback (most recent call last):
+   File "/tmp/getcwd.py", line 9, in <module>
+     os.getcwd()
+ FileNotFoundError: [Errno 2] No such file or directory
+ Error in sys.excepthook:
+ Traceback (most recent call last):
+   File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 76, 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 "/tmp/getcwd.py", line 9, in <module>
+     os.getcwd()
+ FileNotFoundError: [Errno 2] No such file or directory
+ ```
+ 
  Another related issue: bug #1979637
+ 
+ Regression Potential
+ --------------------
+ 
+ There might be a regression that causes capturing Python exception fail.
+ Then reporting them as bugs to Launchpad or the error tracker would not
+ be possible.

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to apport in Ubuntu.
https://bugs.launchpad.net/bugs/1977954

Title:
  apport_python_hook: Crashes if os.getcwd() throws FileNotFoundError

Status in Apport:
  Fix Released
Status in apport package in Ubuntu:
  Fix Released
Status in apport source package in Jammy:
  New

Bug description:
  Test Case
  ---------

  1. Create /tmp/getcwd.py with following content:
  ```
  #!/usr/bin/python3

  import os
  import tempfile

  tempdir = tempfile.mkdtemp()
  os.chdir(tempdir)
  os.rmdir(tempdir)
  os.getcwd()
  ```
  2. Make it executable and execute it.

  It should produce following output:

  ```
  Traceback (most recent call last):
    File "/tmp/getcwd.py", line 9, in <module>
      os.getcwd()
  FileNotFoundError: [Errno 2] No such file or directory
  ```

  instead of:

  ```
  $ /tmp/getcwd.py
  Traceback (most recent call last):
    File "/tmp/getcwd.py", line 9, in <module>
      os.getcwd()
  FileNotFoundError: [Errno 2] No such file or directory
  Error in sys.excepthook:
  Traceback (most recent call last):
    File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 76, 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 "/tmp/getcwd.py", line 9, in <module>
      os.getcwd()
  FileNotFoundError: [Errno 2] No such file or directory
  ```

  Another related issue: bug #1979637

  Regression Potential
  --------------------

  There might be a regression that causes capturing Python exception
  fail. Then reporting them as bugs to Launchpad or the error tracker
  would not be possible.

To manage notifications about this bug go to:
https://bugs.launchpad.net/apport/+bug/1977954/+subscriptions




More information about the foundations-bugs mailing list