Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix crash when uname -rs output is empty #304

Merged
merged 6 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,8 @@ def _uname_info(self) -> Dict[str, str]:

@staticmethod
def _parse_uname_content(lines: Sequence[str]) -> Dict[str, str]:
if not lines:
return {}
props = {}
match = re.search(r"^([^\s]+)\s+([\d\.]+)", lines[0].strip())
if match:
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/testdistros/distro/emptyuname/bin/uname
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo -n
8 changes: 8 additions & 0 deletions tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,14 @@ def test_bad_uname(self):
assert self.distro.uname_attr("name") == ""
assert self.distro.uname_attr("release") == ""

def test_empty_uname(self):
self._setup_for_distro(os.path.join(TESTDISTROS, "distro", "emptyuname"))
self.distro = distro.LinuxDistribution()

assert self.distro.uname_attr("id") == ""
assert self.distro.uname_attr("name") == ""
assert self.distro.uname_attr("release") == ""

def test_usrlibosreleaseonly(self):
self._setup_for_distro(
os.path.join(TESTDISTROS, "distro", "usrlibosreleaseonly")
Expand Down