Skip to content

Commit 1a29c28

Browse files
jefferytobachradsusi
authored andcommitted
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 <[email protected]> Acked-by: Petr Lautrbach <[email protected]>
1 parent d8edd36 commit 1a29c28

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

python/sepolicy/sepolicy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,12 @@ def boolean_desc(boolean):
12401240

12411241

12421242
def get_os_version():
1243+
import subprocess
12431244
system_release = ""
12441245
try:
12451246
import distro
12461247
system_release = distro.name(pretty=True)
1247-
except IOError:
1248+
except (ModuleNotFoundError, OSError, IOError, UnicodeError, subprocess.CalledProcessError):
12481249
system_release = "Misc"
12491250

12501251
return system_release

0 commit comments

Comments
 (0)