From 83d8014a50e46aefc4347a72c3355093f2b4f498 Mon Sep 17 00:00:00 2001 From: Joe Testa Date: Mon, 19 Oct 2020 18:49:52 -0400 Subject: [PATCH] Fixed OpenSSH patch version comparison. (#74) --- src/ssh_audit/software.py | 4 ++-- test/test_version_compare.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ssh_audit/software.py b/src/ssh_audit/software.py index 37f6dd4..02366c4 100644 --- a/src/ssh_audit/software.py +++ b/src/ssh_audit/software.py @@ -83,8 +83,8 @@ class Software: if not re.match(r'^test\d.*$', spatch): spatch = 'z{}'.format(spatch) elif self.product == Product.OpenSSH: - mx1 = re.match(r'^p\d(.*)', opatch) - mx2 = re.match(r'^p\d(.*)', spatch) + mx1 = re.match(r'^p(\d).*', opatch) + mx2 = re.match(r'^p(\d).*', spatch) if not (bool(mx1) and bool(mx2)): if mx1 is not None: opatch = mx1.group(1) diff --git a/test/test_version_compare.py b/test/test_version_compare.py index 367a07c..1eedf7d 100644 --- a/test/test_version_compare.py +++ b/test/test_version_compare.py @@ -136,13 +136,15 @@ class TestVersionCompare: s2 = self.get_openssh_software('2.1.1p2') assert s1.compare_version(s1) == 0 assert s2.compare_version(s2) == 0 - assert s1.compare_version('2.1.1p1') == 0 - assert s1.compare_version('2.1.1p2') == 0 - assert s2.compare_version('2.1.1') == 0 + assert s1.compare_version('2.1.1') == 0 + assert s2.compare_version('2.1.1p2') == 0 + assert s1.compare_version('2.1.1p1') != 0 + assert s1.compare_version('2.1.1p2') != 0 + assert s2.compare_version('2.1.1') != 0 assert s2.compare_version('2.1.1p1') > 0 assert s2.compare_version('2.1.1p3') < 0 - assert s1.compare_version(s2) == 0 - assert s2.compare_version(s1) == 0 + assert s1.compare_version(s2) != 0 + assert s2.compare_version(s1) != 0 def test_openbsd_compare_version_sequential(self): versions = []