Skip to content

Commit

Permalink
Fix crash when uname -rs output is empty (#304)
Browse files Browse the repository at this point in the history
> closes #264
  • Loading branch information
HorlogeSkynet authored Sep 26, 2021
1 parent c613bdf commit d3e9194
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,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 @@ -716,6 +716,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

0 comments on commit d3e9194

Please # to comment.