Skip to content

Commit c00cc79

Browse files
committed
fix: protect against invalid versions coming from firmware
Closes #13
1 parent 25c5b84 commit c00cc79

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

octoprint_firmware_check/checks/firmware_unsafe.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from flask_babel import gettext
55
from octoprint.util.version import get_comparable_version
6+
from packaging.version import InvalidVersion
67

78
from . import AuthorCheck, Check, NegativeCapCheck, Severity
89

@@ -94,7 +95,11 @@ def received(self, line):
9495

9596
def _broken_version(self, line):
9697
version_str = line[len(self.VERSION) :]
97-
version = get_comparable_version(version_str, base=True)
98+
try:
99+
version = get_comparable_version(version_str, base=True)
100+
except InvalidVersion:
101+
version = None
102+
98103
if version is not None and version < self.FIXED_VERSION:
99104
return True
100105
else:
@@ -161,11 +166,17 @@ class MalyanM200Check(Check):
161166
FIXED_VERSION = get_comparable_version("4.0")
162167

163168
def m115(self, name, data):
169+
try:
170+
version = get_comparable_version(data.get("VER", "0"))
171+
except InvalidVersion:
172+
version = None
173+
164174
self._triggered = (
165175
name
166176
and name.lower().startswith("malyan")
167177
and data.get("MODEL") == "M200"
168-
and get_comparable_version(data.get("VER", "0")) < self.FIXED_VERSION
178+
and version is not None
179+
and version < self.FIXED_VERSION
169180
)
170181
self._active = False
171182

@@ -224,7 +235,10 @@ def _extract_repetier_version(self, name):
224235
version = None
225236
if "_" in name:
226237
_, version = name.split("_", 1)
227-
version = get_comparable_version(version, base=True)
238+
try:
239+
version = get_comparable_version(version, base=True)
240+
except InvalidVersion:
241+
pass
228242
return version
229243

230244

0 commit comments

Comments
 (0)