aboutsummaryrefslogtreecommitdiff
path: root/utils/selinux-python/patches/0004-sepolicy-fix-get_os_version-except.patch
blob: f035846d5c11b47b2f6956c33dd155c2d9f58ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
commit 80ba6c49dec9c2c48775e70a4d4564ba5e59eea1
Author: Jeffery To <jeffery.to@gmail.com>
Date:   Mon Jun 19 14:15:45 2023 +0800

    python/sepolicy: Fix get_os_version except clause
    
    This adds more exceptions to be handled by the except clause in
    `get_os_version()`:
    
    * If the `distro` package is not installed, then `import distro` raises
      a `ModuleNotFoundError` exception.
    
    * The distro documentation[1] lists `OSError` and `UnicodeError` as
      exceptions that can be raised.
    
    * Older versions of distro (<= 1.6.0) may also raise
      `subprocessCalledProcessError`[2].
    
    [1]: https://github.com/python-distro/distro/blob/v1.8.0/src/distro/distro.py#L749-L753
    [2]: https://github.com/python-distro/distro/blob/v1.6.0/distro.py#L726-L728
    
    Signed-off-by: Jeffery To <jeffery.to@gmail.com>

--- a/sepolicy/sepolicy/__init__.py
+++ b/sepolicy/sepolicy/__init__.py
@@ -1240,11 +1240,12 @@ def boolean_desc(boolean):
 
 
 def get_os_version():
+    import subprocess
     system_release = ""
     try:
         import distro
         system_release = distro.name(pretty=True)
-    except IOError:
+    except (ModuleNotFoundError, OSError, IOError, UnicodeError, subprocess.CalledProcessError):
         system_release = "Misc"
 
     return system_release